I am trying to create a manuel from validation. I followed a few videos, and also looked up examples on how to create validation forms, and they all work, until one selects the correct name and password. To clarify, if one types in the incorrect username and password it will note: "Wrong username or password". But if it is the correct username or password, I get this strange error:
Illuminate\Auth\EloquentUserProvider::validateCredentials(): Argument #1 ($user) must be of type Illuminate\Contracts\Auth\Authenticatable, App\Models\NewUserStudent_Model given, called in C:\XAMPP\htdocs\Larvavel_NEWTEST\mwcti\vendor\laravel\framework\src\Illuminate\Auth\SessionGuard.php on line 438
I believe it is due to something with my Auth, but am unsure as to what is going on.
Here is the config for my auth:
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\NewUserStudent_Model::class,
'table' => 'student_account',
]
],
Here is my controller:
<?php
namespace App\Http\Livewire\Layout;
use Livewire\Component;
use Illuminate\Support\Facades\Auth;
use App\Models\NewUserStudent_Model;
use Illuminate\Http\Request;
use Illuminate\Auth\Authenticatable;
class Login extends Component
{
use Authenticatable;
public $Email, $Password;
public function loginUser(Request $request)
{
$validated=$this->validate([
'Email' => 'required|email|max:255',
'Password' => 'required|max:255'
]);
// check if password and email matches
if(Auth::attempt($validated))
{
$request->session()->regenerate();
// redirect to home page which allows user to see logout button
return $this->redirect('Home');
}
// if user not correct
$this->addError('Email', 'The password or email is not valid');
}
public function render()
{
return view('livewire.layout.login');
}
}
And finally, here is my view:
<div class="flex flex-col justify-center items-center">
<p class="text-6xl py-20">Login Form</p>
<form wire:submit.prevent="loginUser" class="w-full max-w-lg">
<div class="flex flex-wrap -mx-3 mb-6">
<div class="w-full md:w-1/2 px-3 mb-6 md:mb-0">
<label class="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2" for="grid-first-name">
Email
</label>
<input name="Email" wire:model="Email" class="appearance-none block w-full bg-gray-200 text-gray-700 border-gray-200 rounded py-3 px-4 mb-3 leading-tight focus:outline-none focus:bg-white" id="grid-first-name" type="text" placeholder="Jane">
@error('Email') <span class="text-danger error">{{ $message }}</span>@enderror
</div>
<div class="w-full md:w-1/2 px-3">
<label class="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2" for="grid-last-name">
Password
</label>
<input name="Password" wire:model="Password" class="appearance-none block w-full bg-gray-200 text-gray-700 border border-gray-200 rounded py-3 px-4 leading-tight focus:outline-none focus:bg-white focus:border-gray-500" id="grid-last-name" type="text" placeholder="Doe">
@error('Password') <span class="text-danger error">{{ $message }}</span>@enderror
</div>
</div>
<div class="inline-flex">
<button type="submit" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
Login
</button>
</div>
</form>
<button class="bg-gray-300 hover:bg-gray-400 text-gray-800 font-bold py-2 px-4 rounded-r">
<a wire:navigate href="/Login_Register">Need an Account?</a>
</button>
</div>
EDIT: I decided to throw in my modal file as well:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
class NewUserStudent_Model extends Model
{
use HasFactory;
protected $table = 'student_account';
protected $fillable = ['First_Name', 'Last_Name', 'Email', 'Password'];
}