Migrating from Laravel 4.2 to Laravel 5.0. I moved \App::before(function($request) from my L4.2 filters.php to the L5.0's RouteServiceProvider.php’s boot() method, but I’m getting a
FatalErrorException in Facade.php line 210: Call to undefined method Illuminate\Foundation\Application::before()
error thrown from it. What am I doing wrong?
I haven’t found anything that says this shouldn’t work; an SO question/answer says that it worked for another guy, so I'm not sure where my code is different. I've tried include use Illuminate\Support\Facades\App; and just \App::before, to no avail.
<?php namespace App\Providers;
use Illuminate\Routing\Router;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\App;
class RouteServiceProvider extends ServiceProvider {
protected $namespace = 'App\Http\Controllers';
public function boot(Router $router)
{
App::before(function($request)
{
//My before code
});
}
Try Middleware. In your case you can create a new middleware using the artisan commands. Use the following command for help:
php artisan help make:middleware
Then register your middleware in App\Http\Kernel.php
Finally use Route Group Middleware or Controller Middleware for protection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With