close

[Solved] LARAVEL 8: Class ‘Database\Seeders\DB’ not found

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error LARAVEL 8: Class ‘Database\Seeders\DB’ not found in php. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How LARAVEL 8: Class ‘Database\Seeders\DB’ not found Error Occurs?

Today I get the following error LARAVEL 8: Class ‘Database\Seeders\DB’ not found in php.

How To Solve LARAVEL 8: Class ‘Database\Seeders\DB’ not found Error ?

  1. How To Solve LARAVEL 8: Class 'Database\Seeders\DB' not found Error ?

    To Solve LARAVEL 8: Class 'Database\Seeders\DB' not found Error In the UserSeeder Class add:
    use Illuminate\Support\Facades\DB;

  2. LARAVEL 8: Class 'Database\Seeders\DB' not found

    To Solve LARAVEL 8: Class 'Database\Seeders\DB' not found Error In the UserSeeder Class add:
    use Illuminate\Support\Facades\DB;

Solution 1

In the UserSeeder Class add:

use Illuminate\Support\Facades\DB;

Solution 2

That’s because Laravel will look for DB class in the current namespace which is Database\Seeders.

Since Laravel has facades defined in config/app.php which allows you to use those classes without full class name.

    'DB' => Illuminate\Support\Facades\DB::class,

You can either declare DB class after the namespace declaration with

use DB;

or just use it with backslash.

    \DB::table('users')->insert([

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read

Leave a Comment