Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel 5 如何使用Laravel雄辩模型的where_Laravel 5 - Fatal编程技术网

Laravel 5 如何使用Laravel雄辩模型的where

Laravel 5 如何使用Laravel雄辩模型的where,laravel-5,Laravel 5,我正试图 $orders = \App\Order::with(['Customer'])->where('customers.first', 'LIKE', "{$filterFirst}%"); 然而,我越来越 Column not found: 1054 Unknown column 'customers.first' in 'where clause' (SQL: select * from `orders` where `customers`.`first` LIKE %)

我正试图

 $orders = \App\Order::with(['Customer'])->where('customers.first', 'LIKE', "{$filterFirst}%");
然而,我越来越

 Column not found: 1054 Unknown column 'customers.first' in 'where clause' (SQL: select * from `orders` where `customers`.`first` LIKE %)

如何使用
where
以及
with

您不能仅通过快速加载筛选出相关模型, 正确的做法是循序渐进

  $orders = \App\Order::whereHas('Customer', function ($query) {
     $query->where('customers.first', 'like', "{$filterFirst}%");
})->get();