How to create a cookie for authorization?

Hello!
I'm just starting to understand this framework, so some questions may seem too simple for you, but for me they are still (!) not quite simple. So don't blame me. I very much hope that you will help me to deal with the issues.
There is a method in the controller responsible for the authorisation in the admin:
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) {
 /* Create a cookie. */
 return redirect('backend.dashboard');
 } else {
 $error = 'Not correct login or password.';
 $errors = [
 'errors' => $error
];
 return redirect('backend')->with($errors);
}
}

1. Tell me, please, how do I create a cookie during login and how to use them in the controller, so if any admin is automatically logged in the admin?
2. Correctly whether the compiled handler? If not, how best to do it?
July 8th 19 at 17:14
2 answers
July 8th 19 at 17:16
Why would you reinvent the wheel?
All there in the documentation: https://laravel.ru/docs/v5/authentication
laravel.su/docs/5.2/authentication#authenticating-users
And where here you specify the table you use? I, for example, the table is called "backend_users". - Arthur_McCullough70 commented on July 8th 19 at 17:19
in the model that implementeret authentification interface - Cecelia78 commented on July 8th 19 at 17:22
: Please help me to correct this error - joxi.ru/brRQOjXIMVbyA1.jpg - Arthur_McCullough70 commented on July 8th 19 at 17:25
To correct this error. - Arthur_McCullough70 commented on July 8th 19 at 17:28
July 8th 19 at 17:18
- Read https://laravel.com/docs/5.2/authentication
- Don't use md5, use bcrypt()
How can I use this class for two authorizations?
On the website there will be 2 authorization:
1 - In admin area.
2 - On the website itself.
In the controller because the specified path of the redirect. - Arthur_McCullough70 commented on July 8th 19 at 17:21
: you can redirect to a different url checking the user role, or to make 2 different routes for authorisation and they have to redirect where you want. A lot of options. - Cecelia78 commented on July 8th 19 at 17:24
laravel.su/docs/5.2/authentication#authenticating-users
And where here you specify the table you use? I, for example, the table is called "backend_users". - Arthur_McCullough70 commented on July 8th 19 at 17:27
: laravel.su/docs/5.2/authentication#authenticating-users
And where here you specify the table you use? I, for example, the table is called "backend_users". - Arthur_McCullough70 commented on July 8th 19 at 17:30
: uses the User model ( or the one that is specified in settings) and no matter what there is a table. - Arthur_McCullough70 commented on July 8th 19 at 17:33
in the example I only see the Auth facade. As in this example to use your model? Tell me, please, and then I don't quite understand. - nickolas commented on July 8th 19 at 17:36
: Auth under the hood uses the model specified in settings (in the file config/auth.php in the providers section) - Arthur_McCullough70 commented on July 8th 19 at 17:39
: how can I use one Auth for different tables? - Arthur_McCullough70 commented on July 8th 19 at 17:42
: use different guards. Read the documentation, everything is there. - nickolas commented on July 8th 19 at 17:45
: Please help me to correct this error - joxi.ru/brRQOjXIMVbyA1.jpg - Arthur_McCullough70 commented on July 8th 19 at 17:48
To correct this error. - nickolas commented on July 8th 19 at 17:51
: how to use this hash? Each time a different password( - Arthur_McCullough70 commented on July 8th 19 at 17:54
they should be different. Laravel is able to match them up. - nickolas commented on July 8th 19 at 17:57
: why at authorization nothing is entered in the table, when I click on "Remember me"?
PS box "remember_token" is in the table. - Arthur_McCullough70 commented on July 8th 19 at 18:00
I don't know. If you do everything as written in documentation, that should work. - Arthur_McCullough70 commented on July 8th 19 at 18:03
: look, please.
html form: joxi.ru/xAevlE9U76o8ry.jpg
php handler: joxi.ru/krDje4ViWL8X2p
table: joxi.ru/1A5Xe1lCvkg82E.jpg
The fact that it remembers, but in the table nothing is logged. - Arthur_McCullough70 commented on July 8th 19 at 18:06

Find more questions by tags Laravel