2016-04-15 26 views
2

我有兩個應用,一個工作的路徑文件如下:如何有效地覆蓋Laravel生成的驗證路由?

routes.php文件

<?php 

Route::auth(); 

Route::group(["prefix" => "api"], function() { 
    Route::resource("places", "PlacesController"); 
    Route::resource("users", "UsersController"); 
    Route::group(["prefix" => "auth"], function() { 
     Route::get("/", "[email protected]"); 
     Route::get("logout", 'Auth\[email protected]'); 
    }); 
}); 

Route::get('/', '[email protected]'); 

我有同樣的事情在其他應用程序,但它無法正常工作。我得到一個InvalidArgumentException,因爲它找不到我刪除的login.blade.php文件,因爲它是由Angular處理的。我如何正確並最有效地覆蓋由Route::auth()生成的/ login和/ register GET路由?

+1

難道你不能只是刪除Route :: auth();?或者只是在它之前定義你自己的,首先使用匹配的路線。 –

+1

正確,只是不使用Route :: auth()並自己定義它們,因爲這是所有Route :: auth()正在做的,只是從字面上註冊一些簡單的路由。 – lagbox

+0

這就是我以前的樣子。我只是不認爲這是最好的方式。但好的,謝謝! – Jordan

回答

2

如果你想重寫/登錄和/註冊,你可以聲明Route::auth()像以下後添加這兩種路線:

Route::get('login', ['as' => 'auth.login', 'uses' => 'Auth\[email protected]']); 
Route::get('register', ['as' => 'auth.register', 'uses' => 'Auth\[email protected]']); 

由於應用程序無法找到「login.blade.php」這實際上是從控制器方法返回的,而不是路由,那麼你需要重寫AuthController中的showLoginForm方法並返回你想要加載的視圖。

public function showLoginForm() { 
    return view('path.to.your.view'); 
} 
+0

感謝您的回答,這實際上是對問題的回答,不像那些「不要這樣做,那樣做」。我試圖覆蓋寄存器路由,將其禁用,但在*之前定義它,認爲Laravel不會定義已存在的路由。因爲它實際上是這樣的,所以路由必須在* Route :: auth()之後被覆蓋*。 Upvoted感謝你。 – Arcesilas