S
S
SM_ST2021-06-04 17:56:00
Laravel
SM_ST, 2021-06-04 17:56:00

Why is it throwing an error and not returning a message?

return back() does not work when registering

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use App\Models\User;
use App\Rules\Password;
use Exception;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;

class RegisterController extends Controller
{
    use RegistersUsers;

    protected $redirectTo = RouteServiceProvider::HOME;

    protected function guard()
    {
        return Auth::guard('web');
    }

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

    protected function validator(array $data)
    {
        $messages = [
            'email.required' => 'Введите e-mail',
            'email.email' => 'Введите корректный e-mail',
            'email.max' => 'Длина e-mail не должена превышать 100 символов',
            'email.unique' => 'Данный e-mail уже существует',
            'password.confirmed' => 'Пароли не совпадают',
            'password.required' => 'Введите пароль от аккаунта',
            'password.min' => 'Минимальная длинна пароля 8 символов',
        ];

        return Validator::make($data, [
            'email' => 'required|string|email|max:100|unique:users',
            'password' => ['required', 'string', 'confirmed', 'min:8', new Password]
        ], $messages);
    }

    protected function create(array $data)
    {
        DB::beginTransaction();
        try {
            $user = new User();
            $user->email = $data['email'];
            $user->password = Hash::make($data['password']);
            $user->save();

            DB::commit();
            return $user;
        } catch (Exception $e) {
            DB::rollBack();
            return back()->with('error', $e->getMessage());
        }
    }
}

but throws out
Argument 1 passed to Illuminate\Auth\SessionGuard::login() must implement interface Illuminate\Contracts\Auth\Authenticatable, instance of Illuminate\Http\RedirectResponse given, called in /home/vagrant/projects/Laravel/sberchange/vendor/laravel/ui/auth-backend/RegistersUsers.php on line 36

and dd($e->getMessage()) shows error

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question