重定向以在laravel中创建RegisterController的方法

问题描述 投票:0回答:1

我想在特定动作之后重定向以在laravel中创建registerController的方法。

这样用户可以在注册完成后登录

the screenshoot of the Corresponding error

laravel laravel-routing
1个回答
1
投票

假设您使用的是Laravel提供的默认RegisterController

create是一种受保护的方法,因此您不能将其用作路线中的动作;你可能只在那里使用公共方法。

在默认实现中用作路由操作的公共方法是:

  • showRegistrationForm
  • register(这个在内部称为create

因此要么将他重定向到具有showRegistrationForm作为行动的路线 - 用户可以填写表格,提交并注册。

或者使用User::create()以编程方式在您的特定操作中创建用户。您甚至可以使用返回/创建的User对象以编程方式使用Auth::login()在当前会话中登录用户:

// Creates the record in the database. $newUser returned by the create method is the created User object.
$newUser = \App\User::create([
    'email' => '[email protected]',
    'password' => bcrypt('thepasswordforthenewuser'),
]);
// Pass to the SessionGuard to log him in.
\Auth::login($newUser);
© www.soinside.com 2019 - 2024. All rights reserved.