【发布时间】:2021-08-27 14:13:05
【问题描述】:
我想把这个查询变成laravel方式
select * from brands inner join products on brands.id = products.brandid where categoryid = '1' and (productname like 'search' or brands.name = 'search')
我试过了
$search = $request->allsearch;
$product = DB::table('brands')->join('products', 'brands.id', '=', 'products.brandid')
->where('categoryid', '=', 1)
->where(function ($product, $search) {
$product->where('productname','like','%'.$search.'%')
->orWhere('brands.name','like','%'.$search.'%');
});
但我遇到了一个错误
Too few arguments to function App\Http\Controllers\ProductController::App\Http\Controllers\{closure}(), 1 passed and exactly 2 expected
我已经尝试过使用when,但没有成功。
有什么想法吗?
【问题讨论】:
标签: sql laravel laravel-7 laravel-6