Order Model
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Order extends Model
{
protected $table = 'order';
protected $primaryKey = 'id';
}
获取单列方法
Order::where('id','>=',1000)->pluck('title')->toArray();
//输出
//['苹果 13','苹果 14']
获取 键值形式的方法
Order::where('id','>=',1000)->pluck('title','id')->toArray();
//输出
//[1001=>'苹果 13',1002=>'苹果 14']
使用DB Facades 获取单列和 键值对的方法
use Illuminate\Support\Facades\DB;
//获取单列
$titles = DB::table('order')->where('id','>=',1000)->pluck('title');
foreach ($titles as $title) {
echo $title;
}
//获取键值对
$titles = DB::table('order')->where('id','>=',1000)->pluck('title','id');
foreach ($titles as $id=>$title) {
echo $id,' => ', $title;
}
版权声明:本文为NII.CN的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://nii.cn/4180.html 发布者:nii