非表示の入力フィールドが無効な値に変更された場合、ホームページにリダイレクトしようとしていますが、createメソッドがユーザーインスタンスを返す必要があるため、ここではできません。では、私の選択肢は何ですか?上記のコードでLaravel 5.2 AuthControllerの作成メソッドでリダイレクト
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
*/
protected function create(array $data)
{
$role = Role::where('name', $data['role'])->first();
// Hidden role field has been tampered with! Redirect to homepage.
if(!$role){
return redirect('/');
}
$user = new User();
$user->email = $data['email'];
$user->password = bcrypt($data['password']);
$user->save();
$user->roles()->attach($role);
return $user;
}
致命的なエラー:職人make:auth
で生成AuthController
で
FatalThrowableError in SessionGuard.php line 418:
Type error: Argument 1 passed to Illuminate\Auth\SessionGuard::login() must be an instance of Illuminate\Contracts\Auth\Authenticatable, instance of Illuminate\Http\RedirectResponse given, called in E:\xampp\htdocs\taskie\vendor\laravel\framework\src\Illuminate\Foundation\Auth\RegistersUsers.php on line 63
問題を具体的に説明してください。エラーが表示されたら、それを表示して何をしたいのですか? –
@Chonchol Mahmud最初の質問とエラーメッセージが更新されました。非表示の入力フィールドに有効な値が含まれていない場合、create()メソッド内からユーザーをホームページにリダイレクトします。 –
あなたのルートファイルをホームページに表示します。 –