Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 8 Error Class 'App\User' not found

My auth.php file


'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => \App\Models\User::class,
        ],

Usercontroller file:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\User;

class UserController extends Controller
{
    public function index()
    {
        
        $user = new User();
        $user->name='SYED';
        $user->email='[email protected]';
        $user->password='ssass';
        $user->save();

  
        return view('home');
    }
}

Everything is good to go but I dont know whats up with this code help! i have tried using everything but it does not solve please let me know if I'm doing some mistakes

like image 898
Ali Mohsin Avatar asked Sep 03 '25 07:09

Ali Mohsin


2 Answers

You've used use App\User; in Usercontroller file:

change it as below.

use App\Models\User;

As you're using the namespace of User model is App\Models so you need to use as use App\Models\User;

like image 194
Dilip Hirapara Avatar answered Sep 04 '25 20:09

Dilip Hirapara


Just use this in your controller

use use App\Models\User; instead of use App\User;

use App\Models\User;
like image 45
VIKAS KATARIYA Avatar answered Sep 04 '25 22:09

VIKAS KATARIYA