2014-01-29 25 views
1

我有這個下面的路線和可以爲管理員,我有作秀任何觀點正確Laravel有一個名字分組路由

Route::get('admin/login', array('as'=>'login', function() 
{ 
    return View::make('back_end.login'); 
})); 

app 
    views 
     back_end 
      layouts 
       index.blade.php 
       main.blade.php 
       profile.blade.php 
      login.blade.php 

工作,我想分組與管理perfix。這個動作後並使用

http://localhost/laravel/public/admin/login

http://localhost/laravel/public/admin/profile

網址我得到這個錯誤:

Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException 

這是我的路線:

Route::group(array('prefix' => 'admin'), function() 
{ 
    Route::get('login', function() 
    { 
     return View::make('back_end.login'); 
    }); 

    Route::get('index', array('as'=>'dashboard'), function() 
    { 
     return View::make('back_end.layouts.index'); 
    }); 

    Route::get('profile', function() 
    { 
     return View::make('back_end.layouts.profile'); 
    }); 
}); 

如何解決這個問題的路線。請幫我

+0

運行'composer dump-autoload'並查看是否修復它。 – Dave

回答

2

我最近有同樣的問題。這是我使用的路由的瘦身版本,包括全部抓取。我是路由到控制器,但是您可以用一個函數替換該語法,路由將被處理相同。

Route::group(array('prefix' => 'admin'), function(){ 
    Route::get('/','[email protected]'); 
    Route::resource('users', 'UserController'); 
    Route::get('settings','[email protected]'); 
    /* Catch all route */ 
    Route::any('{all}', function($uri){ 
     return Redirect::to('admin') 
      ->with('flash_error', "The administration page 'admin/$uri' could not be found."); 
    })->where('all', '.*'); 
}); 

一如既往,請務必在更新路由後運行composer dump-autoload。這對我成功運作。你只需要相對的「基礎」路線上的'/'。

0

進行更改(前斜線/添加到admin組內的每個路由)給出爲:

Route::group(array('prefix' => 'admin'), function() 
{ 
    Route::get('/login', function() 
    { 
     return View::make('back_end.login'); 
    }); 

    Route::get('/index', array('as'=>'dashboard'), function() 
    { 
     return View::make('back_end.layouts.index'); 
    }); 

    Route::get('/profile', function() 
    { 
     return View::make('back_end.layouts.profile'); 
    }); 
}); 

應該/login而不是login和同爲每一個。

+0

無法正常工作:'Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException' –

+0

你做了更改後運行'composer dump-autoload',它應該可以工作,我有類似的路由設置並且工作正常。 –

+0

是的。沒有任何更改來運行操作.' Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException' –