回答
代码:
Auth::routes();
其对这个集合路线的shorcut:
// Authentication Routes...
Route::get('login', 'Auth\[email protected]')->name('login');
Route::post('login', 'Auth\[email protected]');
Route::post('logout', 'Auth\[email protected]')->name('logout');
// Registration Routes...
Route::get('register', 'Auth\[email protected]')->name('register');
Route::post('register', 'Auth\[email protected]');
// Password Reset Routes...
Route::get('password/reset', 'Auth\[email protected]')->name('password.request');
Route::post('password/email', 'Auth\[email protected]')->name('password.email');
Route::get('password/reset/{token}', 'Auth\[email protected]')->name('password.reset');
Route::post('password/reset', 'Auth\[email protected]');
所以,你可以代替先用路由列表和注释掉你没有任何途径想要在你的应用程序中
是的,有一种方法
Auth::routes();
远程从你的路由目录中的web.php这条路线。
该路由控制注册。
我想你想限制访问某些页面的访客,只有管理员可以注册一个访客。您可以通过添加您自己的中间件上kernel.php文件象下面这样实现它:
protected $routeMiddleware = [
'authenticated' => \App\Http\Middleware\AuthenticatedMiddleware::class
];
创建中间件之后,你必须使用它,所以你可以去web.php文件在您的路线是将其添加到路线要限制象下面这样:
Route::get('register', 'Auth\[email protected]')->name('register')->middleware('authenticated');
Route::post('register', 'Auth\[email protected]')->middleware('authenticated');
这样的注册仅限于客人,但如果他想注册一些其它管理员管理员仍然能够访问该页面!
不要忘了如下的详细清单,以取代Auth::routes();
:
// Authentication Routes...
Route::get('login', 'Auth\[email protected]')->name('login');
Route::post('login', 'Auth\[email protected]');
Route::post('logout', 'Auth\[email protected]')->name('logout');
// Registration Routes...
Route::get('register', 'Auth\[email protected]')->name('register')->middleware('authenticated');
Route::post('register', 'Auth\[email protected]')->middleware('authenticated');
// Password Reset Routes...
Route::get('password/reset', 'Auth\[email protected]')->name('password.request');
Route::post('password/email', 'Auth\[email protected]')->name('password.email');
Route::get('password/reset/{token}', 'Auth\[email protected]')->name('password.reset');
Route::post('password/reset', 'Auth\[email protected]');
更改路线:
供应商\ laravel \框架的\ src \照亮\路由\路由器。 PHP
public function auth()
{
// Authentication Routes...
$this->get('login', 'Auth\[email protected]')->name('login');
$this->post('login', 'Auth\[email protected]');
$this->post('logout', 'Auth\[email protected]')->name('logout');
// Registration Routes...
//$this->get('register', 'Auth\[email protected]')->name('register');
//$this->post('register', 'Auth\[email protected]');
// Password Reset Routes...
//$this->get('password/reset', 'Auth\[email protected]')->name('password.request');
//$this->post('password/email', 'Auth\[email protected]')->name('password.email');
//$this->get('password/reset/{token}', 'Auth\[email protected]')->name('password.reset');
//$this->post('password/reset', 'Auth\[email protected]');
}
对供应商文件夹中的任何文件进行更改是最糟糕的主意 –
重命名RegisterController任何其他南e或删除它:-)
这看起来很容易!您只需要覆盖app/Http/Controllers/Auth/RegisterController.php
类中的两种方法。请参阅下文,这将阻止显示表单,并且最重要的是阻止直接POST请求到您的注册申请。
/**
* Show the application registration form.
*
* @return \Illuminate\Http\Response
*/
public function showRegistrationForm()
{
return redirect('login');
}
/**
* Handle a registration request for the application.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function register(Request $request)
{
abort(404);
}
虽然上述解决方案的工作,但是,我想改变在App\Http\Controllers\Auth\RegisterController
的middleware
到'auth'
将是最简单的解决方案之一。如果他们想访问任何注册路线,这将把所有访客重定向到登录页面。就像这样:
namespace App\Http\Controllers\Auth;
class RegisterController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
- 1. Laravel 5.4 - 路由不存在
- 2. Laravel 5.4 API路由
- 3. 用户路由Laravel 5.4
- 4. Laravel 5.4 Auth API路由
- 5. Laravel 5.4路由通配符
- 6. 路由排除laravel 5.4
- 7. 路由用户角色Laravel 5.4
- 8. Laravel 5.4:使用参数调用控制器的路由功能
- 9. Laravel 5.4 - 将AuthServiceProvider绑定到路由组?
- 10. Laravel 5.4:阿比路由列表
- 11. laravel 5.4路由组重定向
- 12. Laravel 5.4中的路由操作方法
- 13. Laravel 5.4路由与要求,而params
- 14. Laravel 5.4 null csrf_token()发布到路由
- 15. Laravel 5.4:如何在控制器中不使用路由参数
- 16. 如何在Laravel 5.4中使用Aimeos Laravel包作为localhost路由?
- 17. 禁用angular2路由缓存
- 18. 如何禁用ReactJs的laravel路由
- 19. 禁用路由
- 20. Laravel 5.4:翻译路线
- 21. Laravel 5.4路径输入后
- 22. Laravel路由与控制器
- 23. Laravel路由到控制器
- 24. Laravel路由到控制器
- 25. Laravel动态路由器
- 26. 在symfony中禁用路由缓存
- 27. 可邮寄错误.. laravel 5.3和5.4不能从用户
- 28. 覆盖Laravel 5.4中的默认Auth路由
- 29. Laravel 5.4合并Api路由组与auth中间件?
- 30. Laravel 5.4路由组和资源陷入困境的参数
downvoters这个答案并不完全错了,其只对了一半 –
如果你这样做,你会禁用登录方法也一样,所以这个答案是错的! – user2519032