这里写问题描述
这种写法打印的items是对象
$WebUsers = MovieBasic::when(is_numeric($request->input('status')) , function ($query) use ($request) {
return $query->where('status', $request->input('status'));
})->when($request->input('type'), function ($query) use ($request) {
return $query->where('type', $request->input('type'));
})
->paginate($request->get('pageSize'));
$items = $WebUsers->items();
print_r($items);
这种写法打印的items正常,是数组
$WebUsers =Db::table('movie_basic)->when(is_numeric($request->input('status')) , function ($query) use ($request) {
return $query->where('status', $request->input('status'));
})->when($request->input('type'), function ($query) use ($request) {
return $query->where('type', $request->input('type'));
})
->paginate($request->get('pageSize'));
$items = $WebUsers->items();
print_r($items);
model代码
class MovieBasic extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'movie_basic';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = false;
}
toArray()
谢谢,用model时,我是把整个数组拿去toArray,所以一直不行,其实是要把 数组的每个子项去toArray, 用model和Db::table,返回的东西不同,卡住我好久了