T
T
time_is_always_against_us2021-02-11 15:35:30
Laravel
time_is_always_against_us, 2021-02-11 15:35:30

Where do I go wrong when creating authorization in Laravel?

- Laravel 8
- PHP 7.4
- Googled
- I looked at the Doc (previously I worked on the lara and did authorization, but either something new appeared in version 8, or I forget some trifle).

Controller 1 (super.ru/auth):
Receives email, password data and performs authorization.

$result = Auth::Attempt(['password' => 'superpwd', 'email' => '[email protected]'], true);


Controller 2 (super.ru/testAuthCheck):
Checking authorization. The fact of authorization turns out is not saved in session. Tell me, please, where I'm wrong. Whole controller:
Auth::check(); // false


namespace App\Http\Controllers;

use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Hash;

class AuthUser extends Controller
{
    public function register(Request $request)
    {
        // return $request->all();

        $request->validate([
            'name'       => 'required|string',
            'lastname'   => 'required|string',
            'secondname' => 'required|string',
            'tel'        => 'required|numeric',
            'password'   => 'required|string',
        ]);

        $user = User::create([
            'name'       => $request->name,
            'lastname'   => $request->lastname,
            'secondname' => $request->secondname,
            'tel'        => $request->tel,
            'password'   => Hash::make($request->password),
            'email'      => '',
        ]);

        $login = Auth::login($user);

        return response()->json([
            'message' => 'Регистрация прошла успешно!',
            'login' => $login
        ]);
    }
    public function test(Request $request) {
        $result = Auth::Attempt(['password' => 1, 'email' => '[email protected]'], true);
        dump($result);
    }

    public function test2(Request $request) {
        $result = Auth::check();
        dump($result);
    }

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