Target class [ 〇ed Seeder] does not exist. does not resolve the issue.

Asked 2 years ago, Updated 2 years ago, 47 views

I'm running the laravel app on my mac.I tried to use Ravel's seeder function, so I wrote the code, but it didn't work and the following error occurred.Thank you for your cooperation.

Image Description

The error statement is as follows

 code
$ phpartisan db:seed

Deprecated: PHP Startup: Use of mbstring.internal_encoding is deprecated in Unknown on line 0

   Illuminate\Contracts\Container\BindingResolutionException 

  Target class [PhotoTableSeeder] does not exist.

  at vendor/larvel/framework/src/Illuminate/Container/Container.php —877
    873▕ 
    874 try {
    875 $ $reflector = new ReflectionClass($concrete);
    876 }}catch(ReflectionException$e){
  87877 ththrow new BindingResolutionException("Target class[$concrete] does not exist.",0,$e);
    878▕         }
    879▕ 
    880 ▕ // If the type is not instantiable, the developer is trying to resolve
    881 ▕ // an abstract type such as an Interface or Abstract Class and there is

      +8 vendor frames 
  9 database/seeds/DatabaseSeeder.php:14
      Illuminate\Database\Seeder::call("PhotoTableSeeder")

      +23 vendor frames 
  33 artisan—37
      Illuminate\Foundation\Console\Kernel::handle (Object(Symphony\Component\Console\Input\ArgvInput), Object(Symphony\Component\Console\Output\ConsoleOutput))

I don't know why, but I think it's because I can't read PhotoTableSeeder and it doesn't exist.
I tried to erase the cache and run one of the solutions, the , but it didn't work.

 code
phpartisan cache —clear
phpartisan config —Clear
phpartisan route —clear
phpartisan view —Clear
composer dump-autoload

As a procedure for using the seeder function, I first created the seeder in artisan and described it as follows:

<?php

namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;


// addition
use Illuminate\Support\str;
use App\User;


// Added (20220623)
use Illuminate\Support\Facades\DB;

class PhotoTableSeeder extensions Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        // Added (20220623)
        $param=[
            'user_id'=>fn()=>\App\User::factory()->create()->id,
            'filename' = > Str::random(12).'.jpg',
            'created_at' = > now(),
            'updated_at' = > now(),
        ];
        DB::table('photos') - > insert($param);
    }
}

Next, I wrote this to register the seeder file.

<?php

use Illuminate\Database\Seeder;

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

php laravel

2022-09-30 14:07

1 Answers

https://teratail.com/questions/cvadmps35e88ui

Terateil has solved the problem.In conclusion, it was an error due to the disappearance of the namespace part, which was written by default.Thank you!


2022-09-30 14:07

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.