As i said i'm new to laravel , i don't know about traits
A trait is php. The trait I referred to has the authenticated method I referred to.
You simply copy that method into your login controller to use it. Don't ever modify vendor files. For more on traits see: https://www.php.net/manual/en/language.oop5.traits.php
And
https://www.w3schools.com/php/php_oop_traits.asp
But these are only suggestions, if you want multiple login controllers, that's your choice.
I have tested this below code in AuthenticatesUser.php
protected function authenticated(Request $request, $user) { $type = $user->type; if ($type === 1) { return redirect('/back/permission'); } if ($type === 2) { return redirect('/back'); } return redirect('/login'); }
it works well but it uses to redirect me after logged in
i just want something like validate to prevent users to login by type
You still use the email and password for actual login. Users don't have access to "type". I am sorry if what you are wanting, I don't fully understand.
To help you out with this you might want to look at this package, a lot of laravel users use this package https://github.com/spatie/laravel-permission
They have many examples.
this was your code
public function authenticated(Request $request, $user) { $role = $user->role; if ($role === 'admin') { return redirect('pet/admin'); } if ($role === 'bkeep') { return redirect('account/index'); } return redirect('pet/index'); }
it seems you have role filed in users table that means you can distinguish users by role
in my case i have type field in users table instead of role field
Dear i have used permission and roles package , when you feel free just come to my pc using teamviewer to show you my project it will be very much clear to understand
You may want to put it on GitHub and start a new post that way others can have a look too.
If you understand by checking my project you may solve this easily
You said:
validate to prevent users to login by type
But you use type instead of role. Type should work no different than role. It's just a column name. If you mean form validation, the chapter is: https://laravel.com/docs/7.x/validation
Likewise if you want to protect a whole controller you can write custom middleware so only admin can do all methods in that controller:
public function __construct()
{
$this->middleware('admin'); // just example
}
But in my authorization, and I have admin and bookkeeper, I did not have to write custom middleware. But it's there if you want to use it as well. https://laravel.com/docs/7.x/middleware
Please or to participate in this conversation.