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.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题