Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

learningMonkey's avatar

its showing me App\project error

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

0 likes
31 replies
learningMonkey's avatar

@Sinnbeck ''' ) Tests\Feature\ProjectsTest::test_a_user_can_create_a_project Failed asserting that a row in the table [projects] matches the attributes { "title": "Nam cum qui consequuntur iure aut.", "description": "Et vel et iusto alias similique nam. Eaque veniam incidunt quis quis. Harum atque sint eaque esse. Voluptas dicta est deserunt dolore." }.

'''

learningMonkey's avatar

@Sinnbeck after fixing it shows this ..

Failed asserting that a row in the table [projects] matches the attributes {
    "title": "Nam cum qui consequuntur iure aut.",
    "description": "Et vel et iusto alias similique nam. Eaque veniam incidunt quis quis. Harum atque sint eaque esse. Voluptas dicta est deserunt dolore."
}```


Sinnbeck's avatar

@jaspal Show the test as well then :) Add ``` on the line before and after your code to format it.

1 like
learningMonkey's avatar

@Sinnbeck

  1. Tests\Feature\ProjectsTest::test_a_user_can_create_a_project
Failed asserting that a row in the table [projects] matches the attributes {
    "title": "Culpa odio et iste.",
    "description": "Asperiores libero consequatur optio praesentium fugit facilis exercitationem. Dignissimos sapiente aut dignissimos. Sunt expedita illo minus in."
}.
learningMonkey's avatar

@Sinnbeck

<?php

namespace Tests\Feature;

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

class ProjectsTest extends TestCase
{
    use WithFaker, RefreshDatabase;
    public function test_a_user_can_create_a_project()
    {
        $this->withExceptionHandling();
        $attributes = [
            'title' => $this->faker->sentence,
            'description' => $this->faker->paragraph,
        ];

        $this->post('/projects', $attributes);

        $this->assertDatabaseHas('projects',$attributes);
   
    }
}
Sinnbeck's avatar

@jaspal Check the model Project and see if both title and description are in the $fillable array

1 like
Sinnbeck's avatar

Can you check that a record is indeed inserted?

$this->assertDatabaseCount('projects', 1);
$this->assertDatabaseHas('projects',$attributes);
learningMonkey's avatar

@Sinnbeck after trying your code .. find this issue.

  1. Tests\Feature\ProjectsTest::test_a_user_can_create_a_project
Failed asserting that table [projects] matches expected entries count of 1. Entries found: 0.
Sinnbeck's avatar

@jaspal Try changing this

$this->withExceptionHandling(); //before
$this->withoutExceptionHandling(); //after
learningMonkey's avatar

@Sinnbeck 1) Tests\Feature\ProjectsTest::test_a_user_can_create_a_project

Error: Class "Illuminate\Support\Facades\App\Project" not found
learningMonkey's avatar

@Sinnbeck Route::post('projects', function() { App\Project::create(request(['title', 'description'])); });

Sinnbeck's avatar

@jaspal Change it to

Route::post('projects', function() { 
    \App\Project::create(request(['title', 'description'])); 
});
learningMonkey's avatar

@Sinnbeck done but shows new error.

  1. Tests\Feature\ProjectsTest::test_a_user_can_create_a_project
Error: Class "App\Project" not found
learningMonkey's avatar

@Sinnbeck

use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Route;
// use Illuminate\Support\Facades\App\Project;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});
Route::post('projects', function() {
    \App\Project::create(request(['title', 'description']));
});```
learningMonkey's avatar

@Sinnbeck project.php



namespace App\Models;

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

class Project extends Model
{
    use HasFactory;
    // protected $guarded = [];
    protected $fillable = [
        'title',
        'description'
    ];
}
Sinnbeck's avatar

@jaspal So its in Models

Route::post('projects', function() {
    \App\Models\Project::create(request(['title', 'description']));
});
Sinnbeck's avatar

@jaspal No the Project model. It says it cannot find that file. And you gave it the wrong path (namespace). You forgot \Models\

Please or to participate in this conversation.