Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Class "Illuminate\Foundation\Auth\Student" not found error in laravel new version

I’m new to laravel framework and I’m trying to insert records into users table and students table. The following query works in users table but in the latter showing error Class "Illuminate\Foundation\Auth\Student" not found . could someone please help me. I searched here for similar queries but unfortunately didn’t work for me. Here is my code.

FrondEndController.php

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\User;
use App\Models\Student;
class FrondEndController extends Controller
{
public function homepage(){
$users=User::all();// select *from users;
$q1= User::insert(['name' => 'DR Robin', 'password' =>'winner']);
$q2= Student::insert(['Studentname' => 'DR Robin', 'email' =>'robin@gmail.com']);
$User_Update = User::where("id", '2')->update(["password" =>"eternallove"]);
return $users;
return view('welcome');
}
}

Student.php(Model)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<?php
namespace App\Models;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\Student as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
class Student extends Authenticatable
{
protected $table = 'students';
use HasApiTokens, HasFactory, Notifiable;
protected $fillable = [
'name',
'email',
'password',
];
protected $hidden = [
'password',
'remember_token',
];
protected $casts = [
'email_verified_at' => 'datetime',
];
}

auth.php

<?php
return [
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver'=>'passport',
'provider'=>'Students'
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'Students' => [
'driver' => 'eloquent',
'model' => App\Student::class,
],
],
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
'throttle' => 60,
 ],
 ],
'password_timeout' => 10800,
];

>Solution :

you have to just replace use Illuminate\Foundation\Auth\Student as Authenticatable; to use Illuminate\Foundation\Auth\User as Authenticatable;

Student.php

<?php
...
...
...
use Illuminate\Foundation\Auth\User as Authenticatable;
...
...
...
class Student extends Authenticatable
{
protected $table = 'students';
use HasApiTokens, HasFactory, Notifiable;
protected $fillable = [
'name',
'email',
'password',
];
protected $hidden = [
'password',
'remember_token',
];
protected $casts = [
'email_verified_at' => 'datetime',
];
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading