Such as
Route::group(['prefix'=>'code/{code}','middleware'=>'code'],function(){
});
How can $code be transferred to middleware~
Thank you!
我想大声告诉你2017-05-16 16:57:18
Middleware can also receive additional custom parameters. For example, if your app needs to verify that the user has a given "role" before executing an action, you can create a RoleMiddleware
middleware that accepts the role name as an extra parameter.
Extra parameters of the middleware will be passed in after the $next
parameter:
<?php
namespace App\Http\Middleware;
use Closure;
class RoleMiddleware
{
/**
* Run the request filter.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string $role
* @return mixed
*/
public function handle($request, Closure $next, $role)
{
if (! $request->user()->hasRole($role)) {
// Redirect...
}
return $next($request);
}
}
Middleware parameters can be specified by separating the name and parameters of the middleware with :
when defining routes. Multiple parameters should be separated by commas:
Route::put('post/{id}', ['middleware' => 'role:editor', function ($id) {
//
}]);
For details, please refer to: http://www.golaravel.com/laravel/docs/5.1/middleware/#middleware-parameters