Исключить маршрут из аутентификации Laravel

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

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

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

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

Related of "Исключить маршрут из аутентификации Laravel"

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

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

 // Authentication Routes... $this->get('login', 'Auth\AuthController@showLoginForm'); $this->post('login', 'Auth\AuthController@login'); $this->get('logout', 'Auth\AuthController@logout'); // Password Reset Routes... $this->get('password/reset/{token?}', 'Auth\PasswordController@showResetForm'); $this->post('password/email', 'Auth\PasswordController@sendResetLinkEmail'); $this->post('password/reset', 'Auth\PasswordController@reset'); 

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

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

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

к этому

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

Это приводит к тому, что страница регистра требует, чтобы вы вошли в систему, чтобы связаться с ней.

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

EDIT: и просто добавьте это в свою сеялку, чтобы облегчить жизнь:

  $u1= new App\User; $u1->name = 'Your name'; $u1->email = 'your@mail.com'; $u1->password = bcrypt('yourPassword'); $u1->save(); 

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

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

 // 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\AuthController@showLoginForm'); $this->post('login', 'Auth\AuthController@login'); $this->get('logout', 'Auth\AuthController@logout'); } // Registration Routes... if (in_array('registration', $options)) { $this->get('register', 'Auth\AuthController@showRegistrationForm'); $this->post('register', 'Auth\AuthController@register'); } // Password Reset Routes... if (in_array('password', $options)) { $this->get('password/reset/{token?}', 'Auth\PasswordController@showResetForm'); $this->post('password/email', 'Auth\PasswordController@sendResetLinkEmail'); $this->post('password/reset', 'Auth\PasswordController@reset'); } } else { // Authentication Routes... $this->get('login', 'Auth\AuthController@showLoginForm'); $this->post('login', 'Auth\AuthController@login'); $this->get('logout', 'Auth\AuthController@logout'); // Registration Routes... $this->get('register', 'Auth\AuthController@showRegistrationForm'); $this->post('register', 'Auth\AuthController@register'); // Password Reset Routes... $this->get('password/reset/{token?}', 'Auth\PasswordController@showResetForm'); $this->post('password/email', 'Auth\PasswordController@sendResetLinkEmail'); $this->post('password/reset', 'Auth\PasswordController@reset'); } } 

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

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