Reputation: 3
i did a migration from Laravel 4.2 to 5.0, and reading another questions, i created a new Middleware on my app\http\middleware but, i don't know how implement this to my RouteServiceProvider.php
This is my BeforeMiddleware:
<?php namespace App\Http\Middleware;
use Closure;
class BeforeMiddleware {
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
return $next($request);
}
}
And on my RouteServiceProvider i got this
App::before(function($request)
{
//I think here need to be my code...
});
Upvotes: 0
Views: 990
Reputation: 9464
I had to deal with this same situation some time ago for a CRM, and the ideal approach is to migrate what you had within App::before()
in Laravel 4.2 to a service provider in Laravel 5.0.
At first you can just use the boot()
method located in the AppServiceProvider
, in a way that you can test the waters.
From there you can opt to have a dedicated service provider just to hold this part, such as AppBeforeServiceProvider.
You have mentioned a migration to middleware, but that is actually for filters
coming from Laravel 4.2.
Upvotes: 0
Reputation: 2040
You need to register your middleware in the app/Http/Kernel.php
file.
Here you will find 3 options:
protected $middleware = [..] <-- run on EVERY request
protected $middlewareGroups = ['web'=>...] <-- run on all web routes
protected $routeMiddleware = ['auth'...] <-- run on routes when defined
Upvotes: 1