Reputation: 1920
I would like to send a VARIABLE to my middleware in laravel ,the way I tried is this
Route::get('projects/{id}','projectsController@index')->middleware(['auth', 'project:{id}']);
But all I get in the middleware handle function is '{id}'
where as I want the value of the id variable
public function handle($request, Closure $next,$pid)
{
dd($pid);
return $next($request);
}
I read the documentation on middleware for the version of laravel I am using i.e. 5.2 https://laravel.com/docs/5.2/middleware
But the example given there only talks about passing plain strings as parameters
Upvotes: 1
Views: 718
Reputation: 1920
I figured it out , looks like you don't need to pass query pararmets like this, you can simply pull them using the $request variable like so :
public function handle($request, Closure $next)
{
$pid=$request->id;
return $next($request);
}
Upvotes: 2