2016-02-01 2 views
7

После запуска php artisan make:auth все необходимые маршруты указаны в файле route.php, но есть ли возможность удалить его (я хочу удалить маршрут регистрации)?Исключить маршрут из ларавельской аутентификации

В настоящее время у меня есть

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

Я знаю, что Route::auth() ярлык, чтобы добавить все маршруты. Должен ли я указывать маршруты самостоятельно вместо использования ярлыка?

ответ

7

К сожалению, вы не можете исключить регистр из текущей реализации Route::auth().

Вы должны указать все маршруты вручную, так

// 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]'); 

Я думаю, что это довольно распространенная вещь, чтобы хотеть сделать это было бы неплохо, если бы был параметр метода auth сказать без регистра возможно, вы могли бы подать заявку на проект проекта.

1

Как сказал Марк Дэвидсон, это невозможно из коробки. Но так я справлялся.

Теперь это может быть излишним, но я передаю массив того, что необходимо. Если параметры не переданы, создаются маршруты по умолчанию.

// 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]'); 
    } 
} 

В вашем случае, вероятно, можно просто передать boolean в качестве параметра вместо array. Если логическое значение: true, то не загружайте маршруты register, иначе загрузите все.

Надеюсь, что это поможет.

2

Я просто YOLO и изменить это в RegisterController.php

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

к этому

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

это делает страницу регистра требует от вас быть loged, чтобы добраться до него.

Это взломать. Но это хороший хак.

EDIT: и просто добавить к вашей сеялке, чтобы сделать жизнь проще:

$u1= new App\User; 
    $u1->name = 'Your name'; 
    $u1->email = '[email protected]'; 
    $u1->password = bcrypt('yourPassword'); 
    $u1->save(); 
Смежные вопросы