Answer the question
In order to leave comments, you need to log in
How to make two different authorizations in Laravel?
I am trying to make two different authorizations. One for users, the other for administrators.
I did it with Guard, but it gives me an error, how can I fix it
auth.php
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
'hash' => false,
],
'customers' => [
'driver' => 'token',
'provider' => 'customers',
'hash' => false,
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'customers' => [
'driver' => 'eloquent',
'model' => App\Customer::class,
],
],
if (Auth::guard('customers')->attempt($data)) {
$user = Customer::find(Auth::user()->id);
$user->api_token = Str::random(32);
$user->save();
if ($user->api_token == "") return response()->json([], 200);
return response()->json(['api_token' => $user->api_token], 200);
} else {
return response()->json(['login' => 'Неправильно указан логин или пароль'], 404);
}
Error: Call to undefined method Illuminate\Auth\TokenGuard::attempt() in file /home/a0419894/domains/rostovrepair161.ru/public_html/api/app/Http/Controllers/Auth/CustomerController.php on line 63
Answer the question
In order to leave comments, you need to log in
in guards[] of customer, change the driver to session.
and add api for it
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token ',
'provider' => 'users',
'hash' => false,
],
'customers' => [
'driver' => 'session',
'provider' => 'customers',
'hash' => false ,
],
'
'hash' => false,
],
],
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question