I am attempting to make custom auth roles for a site, i have followed another stack overflow post that seems to get it working but mine always fails, i know the information exists since im dumping and dying the information to screen once Auth::guard fails. The problem is that even though the information exists auth guard fails
if (Auth::guard('Admin')->attempt(['Username' => $Request->input('UName'), 'Password' => $Request->input('Password')])) The information is validated and approved and manages to pass
if (Admins::where('Username', $Request->input('UName'))->exists()) { $AdminDetails = Admins::Where('Username', $Request->input('UName'))->first(); if(Hash::check($Request->input('Password'), $AdminDetails->Password)){ //user details are correct } } I have made the authenticatable for both the user and the admin the code above attempts to authorize the admin, i have also changed the config/auth.php file as shown below
'guards' => [ 'web' => [ 'driver' => 'session', 'provider' => 'users', ], 'api' => [ 'driver' => 'token', 'provider' => 'users', 'hash' => false, ], 'Admin' => [ 'driver' => 'session', 'provider' => 'Admin', ], 'User' => [ 'driver' => 'session', 'provider' => 'User', ], ], 'providers' => [ 'User' => [ 'driver' => 'eloquent', 'model' => App\Models\User::class, ], 'Admin' => [ 'driver' => 'eloquent', 'model' => App\Models\Admins::class, ] // 'users' => [ // 'driver' => 'database', // 'table' => 'users', // ], ], The models are within the correct namespace as shown below with the admin authenticatable
<?php namespace App\Models; use Illuminate\Notifications\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable; class Admins extends Authenticatable { use Notifiable; protected $guard = 'Admin'; protected $fillable = [ 'FName', 'LName', 'Email', 'Password', 'Username' ]; protected $hidden = [ 'password' ]; } and the user authenticatable
<?php namespace App\Models; use Illuminate\Notifications\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable; class Users extends Authenticatable { use Notifiable; protected $guard = 'User'; protected $fillable = [ 'FullName', 'Email', 'CompanyName','ReferedBy','PhoneNumber','MemberStatus','CustomMessage', ]; protected $hidden = [ 'password', 'remember_token', ]; } Laravel 7 displays no errors or anything but the if stament that attempts to log the user in fails
Also the migration for the Admin Model is
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; class CreateAdminsTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('admins', function (Blueprint $table) { $table->id(); $table->string('Username'); $table->string('FName'); $table->string('LName'); $table->string('Email'); $table->string('Password'); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('admins'); } } I am aware this is a lot of information to put in a single question but i know that its all relevant to the problem. Thanks for any help provided.