I am getting a Class 'App\Models\User' not found
error when I try too use the User
class inside a controller class method. I have looked everywhere and tried everything with no luck! Here's what I've tried:
- Check that class exists and is in the right path (it works everywhere else)
- Add
use App\Models\User;
to the top of the controller file and just useUser
- Tried:
new \App\Models\User
- Run:
composer dump-autoload
- Run:
php artisan dump-autoload
- Run:
php artisan clear-compiled
When I do dd(class_exists('App\Models\User'))
, I get \vendor\laravel\framework\src\Illuminate\Support\helpers.php:513:boolean false
which confirms that the class really isn't accessible for some reason.
Any ideas?
EDIT
You will find questions similar to this but not the same. Please read question carefully. I didn't say the controller class was missing. I said a model class (User) was not accessible from inside a particular controller class. And that the model class works everywhere else.
EDIT: Code Excerpt
<?php
use App\Models\User;
use App\Models\Role;
use App\Models\Advert;
use App\Models\AdvertPhoto;
use App\Models\AdvertMetum;
use App\Models\AdvertMetaDatum;
use App\Models\AdvertMetaCategory;
use Illuminate\Support\Facades\View;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\Request;
class AdvertsController extends BaseController {
/**
* Show the form for creating a new resource.
* GET /adverts/create
*
*/
public function create()
{
// New user instance
// dd(class_exists('\App\Models\User')); // Outputs FALSE
$userx = new User; // Throws an Exception
return View::make('adverts.create');
}
}