dimanche 29 novembre 2020

Laravel 8 Class 'Database\Seeders\App\Models\Admin' not found

I'm currently learning on Database Seeding in Laravel 8. When runnning the seed I got an error message

Class 'Database\Seeders\App\Models\Admin' not found

First I created migration database file called Admin.php in App\Models and I put these codes

<?php

namespace App\Models;

use Illuminate\Notification\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
//use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;


class Admin extends Authenticatable
{
    use Notifiable;
    protected $guard = 'admin';
    protected $fillable = [
        'name', 'type','email','password','image','status','created_at','updated_at',
    ];
    protected $hidden = [
        'password', 'remember_token',
    ];
}

After that I created a seeder called AdminsTableSeeder.php and put these codes

<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use DB;

class AdminsTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        DB::table('admins')->delete();
        $adminRecords = [
            [
                'id'=>1, 
                'name'=>'admin', 
                'type'=>'admin',
                'email'=>'admin@admin.com',
                'password'=>'',
                'image'=>'',
                'status'=>1,
            ],
        ];
        foreach ($adminRecords as $key => $record){
            App\Models\Admin::create($record);
        }
    }
}

And finally on DatabaseSeeder.php I put these codes to call AdminsTableSeeder

<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        $this->call(AdminsTableSeeder::class);

    }
}

After I'm done with all of those, I did composer du and trying to run the seed command but I got the error message.

EDIT I already tried to modify the code from

foreach ($adminRecords as $key => $record){
            App\Models\Admin::create($record);
        }

to

foreach ($adminRecords as $key => $record){
            \App\Models\Admin::create($record);
        }

But I stil got the error message like

Seeding: Database\Seeders\AdminsTableSeeder PHP Fatal error: Trait 'Illuminate\Notification\Notifiable' not found in C:\xam pp\htdocs\tobacon_web\app\Models\Admin.php on line 11

Symfony\Component\ErrorHandler\Error\FatalError

Trait 'Illuminate\Notification\Notifiable' not found




Aucun commentaire:

Enregistrer un commentaire