[英]Laravel 5 Route not Found in RouteServiceProvidor
PHP Fatal error: Class 'App\Providers\Route' not found in /home/****/**********/app/Providers/RouteServiceProvider.php on line 28
[Symfony\Component\Debug\Exception\FatalErrorException]
Class 'App\Providers\Route' not found
以上是我試圖運行Artisan時所看到的錯誤。 似乎問題與我的過濾器(我試圖從Laravel 4遷移到5)和Namespacing有關。 我有兩個命名空間,我希望所有這些過濾器適用於:“App \\ Http \\ Controllers \\ API \\ V1”和“App \\ Http \\ Controllers \\ API \\ V2”,但不能為我的生活理解如何在RouteServiceProvidor文件中設置它。 以下是從RSP.php到相關行的代碼。
<?php namespace App\Providers;
use Illuminate\Routing\Router;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
class RouteServiceProvider extends ServiceProvider {
/**
* This namespace is applied to the controller routes in your routes file.
*
* In addition, it is set as the URL generator's root namespace.
*
* @var string
*/
protected $namespace = 'App\Http\Controllers';
/**
* Define your route model bindings, pattern filters, etc.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function boot(Router $router)
{
parent::boot($router);
//Challenges
Route::filter('challenge_general_permission', function($route)
有任何想法嗎?
您的PHP文件位於App\\Providers
命名空間中。
namespace App\Providers;
您試圖使用具有相對類名稱引用的全局類Route
。
Route::filter('challenge_general_permission', function($route)
執行此操作時,PHP假定您需要類App\\Providers\\Route
。 沒有這樣的類 - PHP死了。 你要么告訴PHP你想要全局類Route
\Route::filter('challenge_general_permission', function($route)
或將Route
導入當前名稱空間
namespace App\Providers;
//...
use Route;
@AlanStorms的答案是完全正確的,但我想補充一點,你甚至不必使用Route
facade。 特別是在這種情況下,您可以直接使用$router
對象。 順便說一下: Router
是Route
facade的底層類。 我會這樣做,而不是你現在擁有的:
public function boot(Router $router)
{
parent::boot($router);
//Challenges
$router->filter('challenge_general_permission', function($route)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.