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

rugavy's avatar
Level 10

Fatal error exception 'Class not found'

hey, guys! I need help with a bug. I'm getting this fatal error in my app:

Whoops, looks like something went wrong.
FatalErrorException in EloquentSettingRepository.php line 6:
Class 'Modules\Core\Repositories\Eloquent\EloquentCoreRepository' not found
in EloquentSettingRepository.php line 6

The EloquentCoreRepository class exists in that namespace.

The class EloquentSettingRepository is:

namespace Modules\Core\Repositories\Eloquent;

use Modules\Core\Repositories\SettingRepository;

// this is the line 6
class EloquentSettingRepository extends EloquentCoreRepository  implements SettingRepository {
...
}

And the EloquentCoreRepository class is:

namespace Modules\Core\Repositories\Eloquent;

use Modules\Core\Repositories\CoreRepository;

abstract class EloquentCoreRepository implements CoreRepository
{
...
}

I did composer dump-autoload, php artisan clear-compiled, cache:clear, optimize... but the error persists

Any ideas? I have none. I have already spent more than 1 hour trying to solve this but it seams I can't get to it.

0 likes
11 replies
SaeedPrez's avatar

What happens if you add this line to EloquentSettingRepository..

use Modules\Core\Repositories\Eloquent\EloquentCoreRepository;
rugavy's avatar
Level 10

I've already tried this, but these files are in the same namespace so it won't matter

lancebutler2's avatar

Is it a new namespace? Can you check if composer picked it up in the autoload file? Or dump the autoload for shits and grins?

SaeedPrez's avatar

@rugavy I know, but we have to take every step to make sure.

Anyways, I've seen this also happen when there is an empty space or some misc character in one of the .php files before <?php or like @lancebutler2 mentioned, it's missing in composer

rugavy's avatar
Level 10

it's not a new namespace. I don't understand why EloquentSettingRepository is found but EloquentCoreRepository is not. they are in the same namespace and phpStorm didn't find any errors.

I did composer dump-autoload but the error is still there.

I will add the SettingServiceProvider:

<?php

namespace Modules\Core\Providers;

use Illuminate\Foundation\AliasLoader;
use Illuminate\Support\ServiceProvider;
use Modules\Core\Entities\Eloquent\Setting;
use Modules\Core\Facades\Settings as SettingsFacade;
use Modules\Core\Repositories\Eloquent\EloquentSettingRepository;
use Modules\Core\Repositories\SettingRepository;
use Modules\Core\Support\Settings;

class SettingServiceProvider extends ServiceProvider
{

    /**
     * Indicates if loading of the provider is deferred.
     *
     * @var bool
     */
    protected $defer = false;

    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        $this->registerBindings();

        $this->app['settings'] = $this->app->share(function ($app) {
            return new Settings($app[SettingRepository::class]);
        });

        $loader = AliasLoader::getInstance();
        $loader->alias('Settings', SettingsFacade::class);
    }

    /**
     * Get the services provided by the provider.
     *
     * @return array
     */
    public function provides()
    {
        return [ ];
    }

    private function registerBindings()
    {
        $this->app->singleton(SettingRepository::class, function () {
            return new EloquentSettingRepository(new Setting());
        });

        $this->app->bind(
            \Modules\Core\Contracts\Setting::class,
            Settings::class
        );
    }
}

Is it possible that this error could be generated from here after all?

rugavy's avatar
Level 10

the error appears for every php artisan command as well

d3xt3r's avatar
d3xt3r
Best Answer
Level 29

Check the class file names for any error. Case mismatch, spelling error if any ...

rugavy's avatar
Level 10

OMG I'm the stupidest man alive. my class file was named "EloquentCoreRespository". I lost 2 hours just to figure this out... so stupid :angry: Sorry for wasting your time :flushed:

Snapey's avatar

I've had similar when not quite holding command when pressing s ;-)

1 like
SaeedPrez's avatar

@rugavy

Back in early 2000s, I used to write a lot of code in Perl/CGI and back then you had to put the path to Perl (was something like /usr/bin/perl) on the first line or something...

Anyways, I had this script that would not work no matter what I tried... finally after many hours I decided to re-write the whole thing (few hundred lines) but of course I kept the first line (the Perl path), no point to re-write the path...

Once I was done, it still did not work... finally I just gave up, left the computer angry, exhausted and disappointed..

The next day, I got back and the first thing I notice is that I had a typo in the path, I had written /usr/nin/perl ..... b and n are next to each other on the keyboard..

Long story short, be glad this experience only cost you 2 hours :) We've all been there, it's one of those lessons you have to learn the hard way.

kaur02anumit's avatar

For me it was wrongly specifying the path. I used backslashes instead of forward ones '/'.

Please or to participate in this conversation.