未定义的属性:stdClass::$categories



如何仅直接通过模型查找所有对象,否则此函数将在模型中停止工作(类别和标记附加到模型(

$products = DB::table('products')
->where('title', 'like', '%'.$search.'%')
->get();

视频以更好地了解问题所在-https://youtu.be/44g47p9JAWs

完成后,您可以使用自定义名称访问中间表数据。

use App/Product
$products = Product::with('tags', 'categories')->where('title', 'like', '%'.$search.'%')->get();

最新更新