laravelでphp artisan db:seed すると次のようなエラーが出ます。
seedを実行する前にcomposer dump-autoloadを実行してもうまくいきません。
色々自分で調べても見ましたが、解決できないため助けてください。。
Laravel Framework 8.31.0
PHP 7.3.24
Illuminate\Contracts\Container\BindingResolutionException Target class [DatabaseSeeder] does not exist. at vendor/laravel/framework/src/Illuminate/Container/Container.php:832 828▕ 829▕ try { 830▕ $reflector = new ReflectionClass($concrete); 831▕ } catch (ReflectionException $e) { ➜ 832▕ throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e); 833▕ } 834▕ 835▕ // If the type is not instantiable, the developer is attempting to resolve 836▕ // an abstract type such as an Interface or Abstract Class and there is +23 vendor frames 24 artisan:37 Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)
web.php
1<?php 2 3use Illuminate\Support\Facades\Route; 4use app\Http\Controllers\PostsController; 5 6/* 7|-------------------------------------------------------------------------- 8| Web Routes 9|-------------------------------------------------------------------------- 10| 11| Here is where you can register web routes for your application. These 12| routes are loaded by the RouteServiceProvider within a group which 13| contains the "web" middleware group. Now create something great! 14| 15*/ 16 17// Route::get('/', function () { 18// return view('welcome'); 19// }); 20 21Route::get('/', 'app\Http\Controllers\PostsController@index')->name('top');
PostsTableSeeder.php
1<?php 2 3namespace Database\Seeders; 4 5use app\Post; 6use app\Comment; 7use Illuminate\Database\Seeder; 8use Illuminate\Support\Facades\DB; 9 10class PostsTableSeeder extends Seeder 11{ 12 /** 13 * Run the database seeds. 14 * 15 * @return void 16 */ 17 public function run() 18 { 19 factory(Post::class, 50) 20 ->create() 21 ->each(function ($post) { 22 $comments = factory(Comment::class, 2)->make(); 23 $post->comments()->saveMany($comments); 24 }); 25 } 26}
DatabaseSeeder.php
1<?php 2 3namespace Illuminate\Database\Seeders; 4namespace App\Models\Post; 5use Illuminate\Database\Seeder; 6 7use Database\Seeders; 8 9class DatabaseSeeder extends Seeder 10{ 11 /** 12 * Seed the application's database. 13 * 14 * @return void 15 */ 16 public function run() 17 { 18 $this->call(PostsTableSeeder::class); 19 // \App\Models\User::factory(10)->create(); 20 } 21} 22

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/03/08 10:36 編集
2021/03/08 10:39
2021/03/08 11:12 編集
2021/03/08 11:12
2021/03/08 11:13
2021/03/08 12:15