App\Models\Project instead of App\Project
App\Models\Project::create(request(['title', 'description']));
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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?
App\Models\Project instead of App\Project
App\Models\Project::create(request(['title', 'description']));
Please or to participate in this conversation.