不允许序列化“PDO” - Laravel 使用 Datatable 缓存

问题描述

if (!Cache::store('file')->has('channel')) {
        $products = Channel::select('*');
        Cache::store('redis')->put('channel',$products,86400);
}
$products = Cache::store('redis')->get('channel',[]);

return DataTables::eloquent($products)
      ->addindexColumn()
      ->make(true);

如果我正在尝试,这会提示我“不允许序列化‘PDO’”

if (!Cache::store('file')->has('channel')) {
        $products = Channel::select('*')->get();
        Cache::store('redis')->put('channel',[]);

return DataTables::eloquent($products)
      ->addindexColumn()
      ->make(true);

then datatables throws error of Method Illuminate\Database\Eloquent\Collection::getQuery does not exist

有人可以解决这些问题吗?

解决方法

使用 ::of() 而不是 ::eloquent()。