2016-02-01 21 views
7

Po uruchomieniu php artisan make:auth wszystkie wymagane trasy znajdują się w pliku route.php, ale czy można je usunąć (chcę usunąć trasę rejestracji)?Wyklucz trasę z uwierzytelniania Laravel

Obecnie mam

Route::group(['middleware' => 'web'], function() { 
    Route::auth(); 
}); 

wiem, że Route::auth() jest skrót, aby dodać wszystkie szlaki. Czy muszę sam określać trasy zamiast używać skrótu?

Odpowiedz

7

Niestety nie można wykluczyć rejestrowania z bieżącą implementacją Route::auth().

Trzeba by określić wszystkie szlaki ręcznie tak

// Authentication Routes... 
$this->get('login', 'Auth\[email protected]'); 
$this->post('login', 'Auth\[email protected]'); 
$this->get('logout', 'Auth\[email protected]'); 

// Password Reset Routes... 
$this->get('password/reset/{token?}', 'Auth\[email protected]'); 
$this->post('password/email', 'Auth\[email protected]'); 
$this->post('password/reset', 'Auth\[email protected]'); 

myślę, że jest to dość powszechne, co chce zrobić to byłoby miło, gdyby nie było parametr metody auth znaczy bez rejestru może mógłbyś wysłać wniosek o wycofanie projektu.

1

Jak powiedział Mark Davidson, nie jest to możliwe po wyjęciu z pudełka. Ale tak właśnie się postarałem.

Teraz może to być przesada, ale przekazuję cały szereg potrzebnych informacji. Jeśli nie zostaną przekazane żadne parametry, tworzone są domyślne trasy.

// Include the authentication and password routes 
Route::auth(['authentication', 'password']); 
/** 
* Register the typical authentication routes for an application. 
* 
* @param array $options 
* @return void 
*/ 
public function auth(array $options = []) 
{ 
    if ($options) { 
     // Authentication Routes... 
     if (in_array('authentication', $options)) { 
      $this->get('login', 'Auth\[email protected]'); 
      $this->post('login', 'Auth\[email protected]'); 
      $this->get('logout', 'Auth\[email protected]'); 
     } 

     // Registration Routes... 
     if (in_array('registration', $options)) { 
      $this->get('register', 'Auth\[email protected]'); 
      $this->post('register', 'Auth\[email protected]'); 
     } 

     // Password Reset Routes... 
     if (in_array('password', $options)) { 
      $this->get('password/reset/{token?}', 'Auth\[email protected]'); 
      $this->post('password/email', 'Auth\[email protected]'); 
      $this->post('password/reset', 'Auth\[email protected]'); 
     } 
    } else { 
     // Authentication Routes... 
     $this->get('login', 'Auth\[email protected]'); 
     $this->post('login', 'Auth\[email protected]'); 
     $this->get('logout', 'Auth\[email protected]'); 

     // Registration Routes... 
     $this->get('register', 'Auth\[email protected]'); 
     $this->post('register', 'Auth\[email protected]'); 

     // Password Reset Routes... 
     $this->get('password/reset/{token?}', 'Auth\[email protected]'); 
     $this->post('password/email', 'Auth\[email protected]'); 
     $this->post('password/reset', 'Auth\[email protected]'); 
    } 
} 

Twoim przypadku można chyba tylko zdać boolean jako parametr zamiast na array. Jeśli wartość logiczna to true, nie ładuj tras register, w przeciwnym razie załaduj wszystko.

Mam nadzieję, że to pomaga.

2

Właśnie YOLO i zmienić w RegisterController.php

public function __construct() 
{ 
    $this->middleware('guest'); 
} 

do tego

public function __construct() 
{ 
    $this->middleware('auth'); 
} 

To sprawia, że ​​strona rejestr wymaga się loged się, by go osiągnąć.

To jest hack. Ale to dobry hack.

EDIT: i po prostu dodać to do siewnika, by ułatwić życie:

$u1= new App\User; 
    $u1->name = 'Your name'; 
    $u1->email = '[email protected]'; 
    $u1->password = bcrypt('yourPassword'); 
    $u1->save();