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

Time:07-07

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' =>'[email protected]']);
$User_Update = User::where("id", '2')->update(["password" =>"eternallove"]);
return $users;
return view('welcome');
}
}

Student.php(Model)

<?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,
];

CodePudding user response:

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',
];
}
  • Related