【问题标题】:Serialization of 'PDO' is not allowed - Laravel caching with Datatable不允许序列化“PDO” - Laravel 使用 Datatable 缓存
【发布时间】:2021-04-14 13:13:11
【问题描述】:
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', $products, 86400);
}
$products = Cache::store('redis')->get('channel', []);

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

然后数据表抛出 Method Illuminate\Database\Eloquent\Collection::getQuery 不存在的错误

谁有解决办法?

【问题讨论】:

  • 使用第二个选项,因为您不能序列化查询对象。如果您没有传递 Eloquent 集合,请不要使用 eloquent() 方法。只需使用 of() 并让 Datatables 类找出你传递的内容。
  • 是的,谢谢。

标签: php mysql laravel redis predis


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-06-10
    • 2014-11-28
    • 1970-01-01
    • 1970-01-01
    • 2014-06-20
    • 1970-01-01
    • 1970-01-01
    • 2021-12-12
    相关资源
    最近更新 更多