Как перенаправить пользователя если не прошел валидацию Laravel Jetstream
Я добавил дополнительное условие проверки почты. Если она входит в массив запрещенных почт, то хочу просто направить пользователя без никаких сообщений обратно на главную страницу. Создал EmailRule в котором выполняю проверку. В функцию зоздания пользователя добавил редирект, но получаю такую ошибку:
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 C:\xampp\htdocs\laravel\vendor\laravel\fortify\src\Http\Controllers\RegisteredUserController.php on line 56
<?php
namespace App\Actions\Fortify;
use App\Models\User;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Laravel\Fortify\Contracts\CreatesNewUsers;
use Laravel\Jetstream\Jetstream;
use App\Rules\EmailRule;
class CreateNewUser implements CreatesNewUsers
{
use PasswordValidationRules;
/**
* Validate and create a newly registered user.
*
* @param array $input
* @return \App\Models\User
*/
public function create(array $input)
{
Validator::make($input, [
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => $this->passwordRules(),
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature() ? ['required', 'accepted'] : '',
])->validate();
$validator = Validator::make($input, [
'email' => [new EmailRule()]
]);
if ($validator->fails()) {
return redirect('/');
}
$user = User::create([
'email' => $input['email'],
'password' => Hash::make($input['password']),
]);
}
}
Ответы (1 шт):
Валидации входных параметров нужна для проверки входных параметров. Перенаправление должно быть в контроллере. Подобный вопрос уже был ранее здесь: https://stackoverflow.com/questions/42177044/laravel-5-4-redirection-to-custom-url-after-login