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

apham5's avatar

Laravel 7 "Class not found" with "use" on top.

I'm using Laravel 7 and suddenly running into this weird "Class not found" error even though I'm following the default set up and it has been working fine with other controllers. The error message was simply:

Class 'app\Post' not found

My Post.php file is in the app folder, and my PostController.php file is in the app/Http/Controllers folder. The content is as below:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Auth;

use app\Post;
use app\Course;
use app\Comment;


class PostController extends Controller
{
	....
	public function store(Request $request)
    	{
        	$validator = Validator::make($request->all(), Post::$create_rules, Post::$create_messages); //line causing error

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
	...

I have tried to dump-autoload but that doesn't seem to help. I'm really confused about what's causing this error.

0 likes
5 replies
keizah7's avatar
keizah7
Best Answer
Level 17

Post model namespace is App so use case sensitive name in your import too.

use App\Post;

instead of use app\Post;

1 like
Prokosa's avatar

@keizah correctly noticed. Use editors like PHPStorm. Syntax highlighting will save you from such problems.

1 like
fylzero's avatar

@apham5 If you're running VS Code download the extension PHP Namespace Resolver. Then you can use that to import your classes without having to manually type them.

1 like
apham5's avatar

Thank you! That solved it!

1 like

Please or to participate in this conversation.