Доброго времени суток, уважаемые знатоки. Столкнулся с проблемой аутентификации.
Есть две таблици:
users
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('fname');
$table->string('lname');
$table->string('patronymic');
$table->date('birth_date');
$table->enum('gender', ['Мужкой', 'Женский']);
$table->string('email')->unique();
$table->string('phone')->unique();
$table->decimal('rate');
$table->timestamp('email_verified_at')->nullable();
$table->boolean('mailing')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
и employees
Schema::create('employees', function (Blueprint $table) {
$table->id();
$table->string('fname', 255);
$table->string('lname', 255);
$table->string('pname', 255);
$table->string('avatar', 255)->nullable();
$table->date('birth_date');
$table->string('login', 255)->unique();
$table->string('password', 255);
$table->integer('percent')->nullable()->unsigned();
$table->timestamps();
});
Питаюсь сделать авторизацию для этих пользователей.
auth.php
<?php
return [
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
'hash' => false,
],
'employee' => [
'driver' => 'session',
'provider' => 'employees',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'employees' => [
'driver' => 'eloquent',
'model' => App\Models\Employee::class,
],
],
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
'throttle' => 60,
],
'employees' => [
'provider' => 'employees',
'table' => 'password_resets',
'expire' => 60,
'throttle' => 60,
],
],
];
EmployeeLoginController
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class EmployeeLoginController extends Controller
{
use AuthenticatesUsers;
protected $redirectTo = RouteServiceProvider::EMPLOYEE_HOME;
public function __construct()
{
$this->middleware('guest')->except('logout');
}
public function showLoginForm()
{
return view('auth.employeeLogin');
}
public function username()
{
return 'login';
}
public function redirectTo()
{
return $this->redirectTo;
}
public function logout(Request $request)
{
$this->guard()->logout();
$request->session()->invalidate();
return redirect()->route('auth.employeeLogin');
}
public function guard()
{
return Auth::guard('employee');
}
}
Модель Employee
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use LaravelAndVueJS\Traits\LaravelPermissionToVueJS;
use Spatie\Permission\Traits\HasRoles;
class Employee extends Authenticatable
{
use Notifiable;
protected $guard_name = 'web';
protected $gaurd = 'employee';
protected $guarded = [];
protected $fillable = ['fname', 'lname', 'pname', 'birth_date', 'login', 'password'];
protected $hidden = ['password', 'remember_token'];
protected $casts = [
'email_verified_at' => 'datetime',
'birth_date' => 'date:d.m.Y',
];
public function phones()
{
return $this->morphMany(Phone::class, 'userable');
}
public function emails()
{
return $this->morphMany(Email::class, 'userable');
}
}
routes
Route::get('/dashboard/login', [EmployeeLoginController::class, 'showLoginForm'])->name('loginDashboardForm');
Route::post('/dashboardLogin', [EmployeeLoginController::class, 'login'])->name("loginDashboard");
Использую пакет laravel auth.
Проблема заключаеться в том, что EmployeeLoginController не логинит работника, не создает сессию, хотя логин и пароль отправляеться на нужный роут логина.
Подскажите что я сделал не так или чего я не сделал?