douxi3554
2016-05-07 06:04 阅读 90

在Laravel5.2.31上登录时如何路由和重定向

I'm using laravel5.2.31. I wanna make login cope and when User after login success, redirect to '/'. And I can register cope but I can't login cope and cannot redirect to '/'. I made auth by php artisan make:auth on terminal. And my routes.php is

Route::post('auth/register','Auth\AuthController@postRegister');
Route::post('auth/login', 'Auth\AuthController@postLogin');
Route::group(['middleware' => 'web'], function () {
    Route::get('auth/register','Auth\AuthController@getRegister');
    Route::get('auth/login', 'Auth\AuthController@getLogin');
});

So I can see auth/login page on browser. But I cannot post cope. Now if I inport email and password and push login button, So I redirected to my own login page.

How Can I do it? What's the cause cannot it?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • dongyixun0634 dongyixun0634 2016-05-07 07:02

    As of Laravel 5.2.27 the web middleware is applied by default and so you no longer need to specify it - so feel free to remove it from your routes.

    As for the redirect, you can just add this to your AuthController:

    private $redirectTo = '/';

    This will redirect users to / after successful login or registration.

    点赞 评论 复制链接分享

相关推荐