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

zambie's avatar

Laravel 8 not finding my model in controller

im new to laravel 8 and i spent hours searchin to solve this problem but failed :<

this is the error :

Error Class 'App\Http\Controllers\Quote' not found http://qoutes.test/

QouteController.php:


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Qoute;

class QouteController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
         $quotes = Quote::all();
         return view('index',compact('quotes'));
    }
}

Qoutes.php:


namespace App\Models;

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

class Quote extends Model
{
    use HasFactory;

    public function author()
    {
     return $this->belongsTo('App\Author');
    }
}
0 likes
8 replies
rodrigo.pedra's avatar
Level 56

You have a typo in your import, this:

use App\Models\Qoute;

Should be this:

use App\Models\Quote;
1 like
rodrigo.pedra's avatar

Also maybe you should consider renaming your controller to QuoteController.

Just don't forget to update your routes file in case you rename it

1 like
rodrigo.pedra's avatar

So reading your code again, it seems your Quote class is in a file name Qoutes.php.

That will prevent the autoloader to find the correct class. A class name should match its filename.

So you can:

1 - First alternative

  • Rename your Qoutes.php file to Quotes.php
  • Fix the import in your Controller as I outlined in the my first response.

2 - Second alternative

Rename the class inside Qoutes.php to match the filename, and use that in your controller's method.

So your Qoutes.php file would become:

namespace App\Models;

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

class Qoute extends Model // <<<<< CHANGED HERE
{
    use HasFactory;

    public function author()
    {
     return $this->belongsTo('App\Author');
    }
}

And in your QouteController.php would become:

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Qoute; // NOTE: is choosing this alternative keep this import as is

class QouteController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
         $quotes = Qoute::all(); // <<<<< CHANGED HERE
         return view('index',compact('quotes'));
    }
}

I recommend you renaming both your files and controllers to use Quote instead of Qoute as the first seems to be the correct spell. Unless your project is named Qoute or this the expected spelling in your local language or region.

If you choose to normalize the spelling across your project, don't forget:

  • Class names and file names should match, including the case. So a class named QuoteController should have a filename named QuoteController.php
  • If you change your controller class name and file name, don't forget to update your routes file
  • If you change any class name or filename check if you need to update any other references in other files from your project
1 like
zambie's avatar

Thanks for the responses, idk what the real problem is but i just tried to paste this again even though its the same and it magically worked lolol. Im more confused now but thanks ! hahha

1 like
rodrigo.pedra's avatar

Well glad you got it working, but I still would review if class names and filenames match.

Have a nice day =)

1 like
zambie's avatar

OH! omg im so dumb. so its "quo" not "qou" T^T thank u so much for pointing it out.

1 like
rodrigo.pedra's avatar

No big deal. This kind of typos can help to all of us.

Maybe when you were pasting or tweaking the code you fixed it without noticing.

Have a nice day =)

2 likes

Please or to participate in this conversation.