JacobFHolland
3 weeks ago

Laravel claims a model is not found (but it definitely exists)

Posted 3 weeks ago by JacobFHolland

I am currently following the TDD birdbox videos and am experiencing an issue with Laravel claiming that the Project model cannot be found. I am on the very start of it doing my first test. I have confirmed up until the part where you need to make the Model, and everything functions as it should in the video until then.

ProjectsTest.php


namespace Tests\Feature;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;

class ProjectsTest extends TestCase
{
    use WithFaker, RefreshDatabase;

    /** @test */
    public function user_can_create_a_project()
    {
        //Disables Exception Handling so routes can be ignored temporarily
        $this->withoutExceptionHandling();

        //Create an array of fields to check in the table
        $attributes = [
            'title'=> $this->faker->sentence,
            'description' => $this->faker->paragraph
        ];

        //Make POST request to route
        $this->post('/projects',$attributes);

        //Assert Database has the fields in the table
        $this->assertDatabaseHas('projects',$attributes);
    }
}

web.php


use Illuminate\Support\Facades\Route;


Route::get('/', function () {
    return view('welcome');
});

Route::post('/projects', function(){
	//validate
	
	//persist
	App\Project::create(request(['title', 'description']));

	//redirect
});

Project.php


namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Project extends Model
{
    use HasFactory;

    
}

And I am getting the error in PHPUnit


There was 1 error:

1) Tests\Feature\ProjectsTest::user_can_create_a_project
Error: Class 'App\Project' not found

I can very clearly see that Project.php is in my app\Models folder as created by the command line. Any ideas?

Please sign in or create an account to participate in this conversation.