doujuxin7392 2018-04-12 20:39
浏览 63
已采纳

在会话中存储什么以在登录后将用户重定向到注册页面?

I want to have a context like this image:

enter image description here

A unauthenticated user can access the congress details page single.blade.php and he can select the quantities that he want for each ticket type. After click Next, if is not authenticated he goes to the "login.blade.php" to login. After login he should be redirected to the registration.blade.php.

So for the first screen I have this from action and route:

<form method="post" 
action="{{route('congresses.registration', 
['id' => $congress->id, 'slug' => $congress->slug])}}">


Route::get('/congress/{id}/{slug?}', [
    'uses' => 'FrontController@show',
    'as'   =>'congresses.show'
]);

For the user access the registration page he should be authenticated, so there is this route:

Route::group(['prefix' => '', 'middleware' => 'auth'], function(){
        Route::post('/congress/{id}/{slug?}/registration', [
        'uses' => 'RegistrationController@storeQuantity',
        'as'   =>'congresses.registration'
    ]);
  }

Doubt: Do you know which data and what is necessary to store in session so is possible to redirect the user to the registration page after login?

With the code I have for now without using sessions, the user select the quantities and click in "Next", then the user introduce the email and password click in "Confirm" and then the user is redirected to "http://layout.test/congress/1/congress-title-test/registration" but it appears always "Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException".

LoginController:

class LoginController extends Controller
{
    use AuthenticatesUsers;


    protected $redirectTo = '/';

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

    protected function authenticated(Request $request, $user)
    {
        return redirect()->intended($this->redirectTo);

    }
}

Routes:

Middleware group                                URI                                       NAME                            ACTION
    Get | Head | Web                            /                                          /                      App\Http\Controllers\FrontController@index

    Get | Head | Web                     congress/{id}/{slug?}                   congresses.show               App\Http\Controllers\FrontController@show

    Get | Head | POST | PUT 
    | PATCH | DELETE | 
    OPTIONS | WEB | AUTH             congress/{id}/{slug?}/registration     congresses.registration App\Http\Controllers\RegistrationController@storeQuantity

I also have the default laravel auth routes.

  • 写回答

1条回答 默认 最新

  • dongou3158 2018-04-12 21:07
    关注

    A. screen 1 should submit to a route protected by auth middleware.

    B. the route protected by auth middleware should return screen 3

    A-a. The auth middleware will take care of screen 2 and move them on to screen 3 when they are registered/logged in.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?