A
A
Anton2016-06-02 13:16:27
Laravel
Anton, 2016-06-02 13:16:27

How to create a cookie on login?

Hello!
I'm just starting to understand this framework, so some questions may seem too simple for you, but for me they are so far (!) Not quite simple. So don't judge. I really hope you can help me with my questions.
There is such a method in the controller responsible for authorization in the admin panel:

public function enter(Request $request)
{
    $login = $request->input('login');
    $password = md5($request->input('password'));
    $language = $request->input('language');

    $user = User::where('login', $login)->andWhere('password', $password)->first();
    if ($user) {
        /* Создать cookie. */
        return redirect('backend.dashboard');
    } else {
        $error = 'Не правильно введены логин или пароль.';
        $errors = [
            'errors' => $error
        ];
        return redirect('backend')->with($errors);
    }
}

1. Tell me, please, how can I create cookies during authorization and how to use them in the controller, so that if they are available, the admin will automatically be authorized in the admin panel?
2. Is the handler well composed? If not, what is the best way to do it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
WebDev, 2016-06-02
@kirill-93

Why are you reinventing the wheel?
Everything is in the documentation: https://laravel.ru/docs/v5/authentication

D
D', 2016-06-02
@Denormalization

- Read https://laravel.com/docs/5.2/authentication
- Don't use md5, use bcrypt()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question