Laravel 5: DB Seed class not found

Laravel 5: DB Seed class not found

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Laravel 5: DB Seed class not found

When running php artisan db:seed in Laravel 5, the framework attempts to autoload your seeder classes via the DatabaseSeeder. If you receive a ReflectionException stating that MemberInvitationSeeder does not exist, despite the file being present in the codebase, the issue almost always stems from how the autoloader interacts with the autoloading mechanism in older Laravel versions.

In Laravel 5, the seeder classes are discovered dynamically. The framework looks for a class named <ClassName>Seeder within your application directory. When you call $this->call('MemberInvitationSeeder'), Laravel expects to find a fully qualified class name matching that string. However, simply placing the file in the same directory as DatabaseSeeder.php is not enough; the autoloader must be able to resolve that class name immediately.

The error persists even after running composer dump-autoload because of how Laravel 5 handles autoloading relative to namespace definitions. If your MemberInvitationSeeder class does not define a specific namespace, or if the namespace declaration in the file does not match the directory structure exactly, the autoloader cannot map the class name to the file path correctly during runtime.

Fixing the Namespace Mismatch

The most common cause of this issue is an implicit namespace assumption that breaks in Laravel 5's strict autoloading context. While Laravel 4 and earlier were more lenient regarding namespaces, Laravel 5 requires explicit namespace declarations for seeder classes to be reliably found via string references like 'MemberInvitationSeeder'.

First, ensure your MemberInvitationSeeder class is inside a valid namespace. If the file is located in app/DatabaseSeeders, the class should look like this:

<?php

namespace App\DatabaseSeeders;

use Illuminate\Database\Seeder;
use App\MemberInvitation;

class MemberInvitationSeeder extends Seeder
{
    public function run()
    {
        MemberInvitation::truncate();

        MemberInvitation::create([
            'id' => 'BlahBlah',
            'partner_id' => 1,
            'fisrt_name' => 'Thats',
            'last_name' => 'Me',
            'email' => 'me@mymail.com',
            'mobile_phone' => '444-342-4234',
            'created_at' => new DateTime
        ]);
    }
}

Note the namespace App\DatabaseSeeders; statement. Without this, the class is effectively in the global namespace. When Laravel tries to resolve MemberInvitationSeeder, it looks for App\MemberInvitationSeeder. If the file has no namespace, the autoloader fails to find it because it cannot construct the full path based on a partial name match in older versions of the framework.

Updating the DatabaseSeeder Call

Once the namespace is defined, you must ensure the call in DatabaseSeeder matches the class name exactly, including the namespace if you intend to use the fully qualified name. However, Laravel 5's seeder discovery usually resolves names relative to the root namespace if the class is marked up correctly.

If you want to be explicit and avoid any ambiguity, update your DatabaseSeeder as follows:

<?php

use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;

class DatabaseSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        Model::unguard();

        // Use the fully qualified class name if relative resolution fails
        $this->call('App\DatabaseSeeders\MemberInvitationSeeder');
        
        // Or simply ensure the class is autoloadable with just:
        // $this->call('MemberInvitationSeeder'); 
    }
}

In most cases, defining the namespace on the seeder class allows $this->call('MemberInvitationSeeder') to work correctly because Laravel maps the short name to the fully qualified path based on the declared namespace.

Verifying Autoload Configuration

If adding the namespace declaration does not resolve the issue, inspect your composer.json. The autoload section must include the psr-4 mapping for your application namespace. Run composer dump-autoload after ensuring that the file exists and is valid PHP code.

composer dump-autoload

This regenerates the autoload files (vendor/composer/autoload_class_maps.php and similar). If the class still cannot be found, check that you are not running the seeder command from a different working directory or environment where the app namespace might not be loaded.

Best Practices for Seeders

For future projects, consider using fully qualified class names in your $this->call() method to avoid ambiguity, especially if you move files around:

$this->call(App\DatabaseSeeders\MemberInvitationSeeder::class);

This approach works consistently across Laravel versions and eliminates reliance on string magic. Additionally, ensure that your model MemberInvitation is correctly mapped in the App namespace, as seen in your use App\MemberInvitation; statement. If that model also lacks a proper namespace or file placement, you might encounter similar resolution errors elsewhere.

If you continue to face issues with legacy Laravel 5 codebases, upgrading to Laravel 5.5 or higher is recommended, as the seeder discovery process became more robust and less dependent on implicit namespace assumptions.

Our network