When using a variable inside a Closure scope, you must use the “use” keyword to pass the variable into the Closure: foreach ($user->locations as $location) { $r = TableName::where(‘id’, ‘<>’, $this->id) ->where(function ($q) use ($code) { // SEE HERE $q->where(‘name’, $code) ->orWhere(‘alias’, $code); }) ->get(); } If you have an array variable like $requestParam[‘name’], you need to define it before the query statement: $name = $requestParam[‘name’]; $lastRecordResult = YrModel::where(‘type’, self::table) ->where(function ($q) use ($name) { $q->where(‘name’, $name) ->orWhere(‘alias’, $name); }) ->where(‘t_id’, $requestParam[‘t_id’]) ->where(‘v_id’, $requestParam[‘v_id’]) ->count();
Category: Laravel
How To Get Current Route Name Path in Laravel 5.4 ?
Here I am going to share you problem that most of the laravel beginner found when developed a project with laravel. You can get to know about the solution for the issue ‘get current route name path in laravel 5.4’ with this article. Get Current Route Name Path From view (blade template) – You can get the current route name path from view (blade template) by using below code – {{ url()->current() }} // It will return route name with url {{ Request::path() }} // It will return only route…