php - Laravel Advanced Wheres how to pass variable into function? -
example in doc:
db::table('users') ->whereexists(function($query) { $query->select(db::raw(1)) ->from('orders') ->whereraw('orders.user_id = users.id'); }) ->get(); but if need use external variable that:
->where('city_id', '=', $this->city->id) ->where(function($query) { $query->where('name', 'like', '%'.$searchquery.'%') ->orwhere('address', 'like', '%'.$searchquery.'%') }) for created new property , accessed through $this->, there more convenient way?
you can pass necessary variables parent scope closure use keyword.
for example:
db::table('users')->where(function ($query) use ($activated) { $query->where('activated', '=', $activated); })->get(); more on here.