运行php artisan make:auth
后,所有必需的路由都在route.php
文件中,但是是否可以删除一个(我想删除注册路由)?
目前我有
Route::group(['middleware' => 'web'], function () {
Route::auth();
});
我知道Route::auth()
是添加所有路由的快捷方式。我应该自己指定路线而不是使用快捷方式吗?
您无法排除使用当前实现的 Route::auth()
注册。
您必须手动指定所有路由,以便
// Authentication Routes...
$this->get('login', 'AuthAuthController@showLoginForm');
$this->post('login', 'AuthAuthController@login');
$this->get('logout', 'AuthAuthController@logout');
// Password Reset Routes...
$this->get('password/reset/{token?}', 'AuthPasswordController@showResetForm');
$this->post('password/email', 'AuthPasswordController@sendResetLinkEmail');
$this->post('password/reset', 'AuthPasswordController@reset');
我认为这是一件相当普遍的事情,如果auth
方法有一个参数说没有注册,也许你可以向项目提交拉取请求,那就太好了。
在新版本中,您可以这样做(在您的 web.php 文件中):
Auth::routes(['register'=>false]);
正如马克·戴维森所说,这不可能开箱即用。但这就是我的处理方式。
现在它可能有点矫枉过正,但我传递了一系列需要的东西。如果未传递任何参数,则创建默认路由。
// 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', 'AuthAuthController@showLoginForm');
$this->post('login', 'AuthAuthController@login');
$this->get('logout', 'AuthAuthController@logout');
}
// Registration Routes...
if (in_array('registration', $options)) {
$this->get('register', 'AuthAuthController@showRegistrationForm');
$this->post('register', 'AuthAuthController@register');
}
// Password Reset Routes...
if (in_array('password', $options)) {
$this->get('password/reset/{token?}', 'AuthPasswordController@showResetForm');
$this->post('password/email', 'AuthPasswordController@sendResetLinkEmail');
$this->post('password/reset', 'AuthPasswordController@reset');
}
} else {
// Authentication Routes...
$this->get('login', 'AuthAuthController@showLoginForm');
$this->post('login', 'AuthAuthController@login');
$this->get('logout', 'AuthAuthController@logout');
// Registration Routes...
$this->get('register', 'AuthAuthController@showRegistrationForm');
$this->post('register', 'AuthAuthController@register');
// Password Reset Routes...
$this->get('password/reset/{token?}', 'AuthPasswordController@showResetForm');
$this->post('password/email', 'AuthPasswordController@sendResetLinkEmail');
$this->post('password/reset', 'AuthPasswordController@reset');
}
}
对于您的情况,您可能只将boolean
作为参数传递,而不是传递array
。如果布尔值true
则不要加载register
路由,否则加载所有内容。
希望对您有所帮助。
我只是YOLO并在注册控制器中更改它.php
public function __construct()
{
$this->middleware('guest');
}
对此
public function __construct()
{
$this->middleware('auth');
}
这使得注册页面要求您登录才能访问它。
这是一个黑客。但这是一个很好的黑客。
编辑:只需将其添加到您的播种机中,即可让生活更轻松:
$u1= new AppUser;
$u1->name = 'Your name';
$u1->email = 'your@mail.com';
$u1->password = bcrypt('yourPassword');
$u1->save();
您可以像这样将重定向添加到/register 路由:
<?php
Auth::routes();
// prevent registration, this needs to be after Auth::routes()
Route::redirect('register', '/home', 301);