Reputation: 1632
I have got this error so many times in Laravel as using model classes that says this class does not exists which it does. one of them was when i ran App\Post::count()
with tinker and got this:
PHP Fatal error: Class 'App/Post' not found in Psy Shell code on line 1
and one was when i tried to seed the DB with model. this is the model content:
namespace App;
use Illuminate\Database\Eloquent\Model;
class Dog extends Model
{
//
}
and this is the Seeder:
<?php
use Illuminate\Database\Seeder;
use \App\Dog;
class DogsTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Dog::query()->create(['name'=>'jack']);
}
}
with this error: Class 'App\Dog' not found.and this is for every model i create.
any solution? (Laravel -V: 5.4, PHP -V: 7.2, Apache webserver)
Upvotes: 2
Views: 6370
Reputation: 21
I was having a similar problem with App\Post::count()
but it works when I add Models before the Post. You can try that one too.
App\Models\Post::count()
So, in your case:
App\Models\Dog
Upvotes: 0
Reputation: 775
Sometimes it is necessary to clear the cache, this command worked in my case:
composer dump-autoload
I hope it works for you too
regards
Upvotes: 4
Reputation: 434
After trying to fix the same issue about half hour on laravel 5.8 with php v7.2, I noticed, that my php file started with <?
output delimiter. Changing <?
to <?php
fixed my problem.
Upvotes: 2
Reputation: 63
On some servers you need to prefix App with \ like: namespace \App;
Also after the above change:
Upvotes: 0