Ví dụ trong doc:Laravel Advanced Wheres cách chuyển biến thành hàm?
DB::table('users')
->whereExists(function($query)
{
$query->select(DB::raw(1))
->from('orders')
->whereRaw('orders.user_id = users.id');
})
->get();
Nhưng nếu tôi cần phải sử dụng biến bên ngoài như thế:
->where('city_id', '=', $this->city->id)
->where(function($query)
{
$query->where('name', 'LIKE', '%'.$searchQuery.'%')
->orWhere('address', 'LIKE', '%'.$searchQuery.'%')
})
Để bây giờ tôi tạo ra tài sản mới và truy cập nó thông qua $this->
, nhưng có bất kỳ thuận tiện hơn đường?
Cảm ơn bạn, @kajetons –
@kajetons này rất hữu ích –
Cảm ơn @ kajetons.it đã giúp tôi rất nhiều – iCoders