https://i.stack.imgur.com/PkCwB.png : Error Screenshot
i've installed a packageernysans/laraworld
with composer. Added respectiveproviders
&aliases
inapp/config/app.php
. Then, i run this -php artisan vendor:publish --provider="ErnySans\Laraworld\LaraworldServiceProvider"
&php artisan migrate
. After that, when runningphp artisan db:seed
,am getting the above error. i've already gone through this link in laravel 8 with seeding , i has this issue Target class [TableSeeder] does not exist .Triedcomposer dump-autoload
. How can i fix this?
database/seeders/DatabaseSeeder.php
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Database\Seeds\CountriesTableSeeder;
class DatabaseSeeder extends Seeder
{
public function run()
{
$this->call([CountriesTableSeeder::class,TimeZonesTableSeeder::class,LanguagesTableSeeder::class]);
}
}
database/seeds/CountriesTableSeeder.php
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use ErnySans\Laraworld\Models\Countries;
class CountriesTableSeeder extends Seeder
{
public function run()
{
Countries::truncate();
$JSON_countries = Countries::allJSON();
foreach ($JSON_countries as $country) {
Countries::create([
'capital' => ((isset($country['capital'])) ? $country['capital'] : null),
'citizenship' => ((isset($country['citizenship'])) ? $country['citizenship'] : null),
'country_code' => ((isset($country['country_code'])) ? $country['country_code'] : null),
'currency' => ((isset($country['currency'])) ? $country['currency'] : null),
'currency_code' => ((isset($country['currency_code'])) ? $country['currency_code'] : null),
'currency_sub_unit' => ((isset($country['currency_sub_unit'])) ? $country['currency_sub_unit'] : null),
'full_name' => ((isset($country['full_name'])) ? $country['full_name'] : null),
'iso_3166_2' => ((isset($country['iso_3166_2'])) ? $country['iso_3166_2'] : null),
'iso_3166_3' => ((isset($country['iso_3166_3'])) ? $country['iso_3166_3'] : null),
'name' => ((isset($country['name'])) ? $country['name'] : null),
'region_code' => ((isset($country['region_code'])) ? $country['region_code'] : null),
'sub_region_code' => ((isset($country['sub_region_code'])) ? $country['sub_region_code'] : null),
'eea' => (bool)$country['eea'],
'calling_code' => ((isset($country['calling_code'])) ? $country['calling_code'] : null),
'currency_symbol' => ((isset($country['currency_symbol'])) ? $country['currency_symbol'] : null),
]);
}
}
}
composer.json
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
There are two options
You should put theCountriesTableSeeder
in the seeders folder with the namespace of
namespace Database\Seeders;
You should use theCountriesTableSeeder
insideDatabaseSeeder
as below
use Database\Seeds\CountriesTableSeeder;
database/seeder/DatabaseSeeder.php
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Database\Seeds\CountriesTableSeeder;
class DatabaseSeeder extends Seeder
{
public function run()
{
$this->call([CountriesTableSeeder::class,TimeZonesTableSeeder::class,LanguagesTableSeeder::class]);
}
}
=============================================
Solution 2 Complete Code
=============================================
Update your code with below contents:
database/seeders/DatabaseSeeder.php
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Database\Seeds\CountriesTableSeeder;
class DatabaseSeeder extends Seeder
{
public function run()
{
$this->call([CountriesTableSeeder::class,TimeZonesTableSeeder::class,LanguagesTableSeeder::class]);
}
}
database/seeds/CountriesTableSeeder.php
<?php
namespace Database\Seeds;
use Illuminate\Database\Seeder;
use ErnySans\Laraworld\Models\Countries;
class CountriesTableSeeder extends Seeder
{
public function run()
{
Countries::truncate();
$JSON_countries = Countries::allJSON();
foreach ($JSON_countries as $country) {
Countries::create([
'capital' => ((isset($country['capital'])) ? $country['capital'] : null),
'citizenship' => ((isset($country['citizenship'])) ? $country['citizenship'] : null),
'country_code' => ((isset($country['country_code'])) ? $country['country_code'] : null),
'currency' => ((isset($country['currency'])) ? $country['currency'] : null),
'currency_code' => ((isset($country['currency_code'])) ? $country['currency_code'] : null),
'currency_sub_unit' => ((isset($country['currency_sub_unit'])) ? $country['currency_sub_unit'] : null),
'full_name' => ((isset($country['full_name'])) ? $country['full_name'] : null),
'iso_3166_2' => ((isset($country['iso_3166_2'])) ? $country['iso_3166_2'] : null),
'iso_3166_3' => ((isset($country['iso_3166_3'])) ? $country['iso_3166_3'] : null),
'name' => ((isset($country['name'])) ? $country['name'] : null),
'region_code' => ((isset($country['region_code'])) ? $country['region_code'] : null),
'sub_region_code' => ((isset($country['sub_region_code'])) ? $country['sub_region_code'] : null),
'eea' => (bool)$country['eea'],
'calling_code' => ((isset($country['calling_code'])) ? $country['calling_code'] : null),
'currency_symbol' => ((isset($country['currency_symbol'])) ? $country['currency_symbol'] : null),
]);
}
}
}
=================================
Solution 1 Complete Code:
=================================
database/seeders/DatabaseSeeder.php
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
public function run()
{
$this->call([CountriesTableSeeder::class,TimeZonesTableSeeder::class,LanguagesTableSeeder::class]);
}
}
NOTE: Move your CountriesTableSeeder.php inside theseeders
folder
database/seeders/CountriesTableSeeder.php
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use ErnySans\Laraworld\Models\Countries;
class CountriesTableSeeder extends Seeder
{
public function run()
{
Countries::truncate();
$JSON_countries = Countries::allJSON();
foreach ($JSON_countries as $country) {
Countries::create([
'capital' => ((isset($country['capital'])) ? $country['capital'] : null),
'citizenship' => ((isset($country['citizenship'])) ? $country['citizenship'] : null),
'country_code' => ((isset($country['country_code'])) ? $country['country_code'] : null),
'currency' => ((isset($country['currency'])) ? $country['currency'] : null),
'currency_code' => ((isset($country['currency_code'])) ? $country['currency_code'] : null),
'currency_sub_unit' => ((isset($country['currency_sub_unit'])) ? $country['currency_sub_unit'] : null),
'full_name' => ((isset($country['full_name'])) ? $country['full_name'] : null),
'iso_3166_2' => ((isset($country['iso_3166_2'])) ? $country['iso_3166_2'] : null),
'iso_3166_3' => ((isset($country['iso_3166_3'])) ? $country['iso_3166_3'] : null),
'name' => ((isset($country['name'])) ? $country['name'] : null),
'region_code' => ((isset($country['region_code'])) ? $country['region_code'] : null),
'sub_region_code' => ((isset($country['sub_region_code'])) ? $country['sub_region_code'] : null),
'eea' => (bool)$country['eea'],
'calling_code' => ((isset($country['calling_code'])) ? $country['calling_code'] : null),
'currency_symbol' => ((isset($country['currency_symbol'])) ? $country['currency_symbol'] : null),
]);
}
}
}
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
Laravel is a free open source PHP framework that came out in 2011. Since then, it has been able to become the framework of choice for web developers. One of the main reasons for this is that Laravel makes it easier, faster, and safer to develop complex web applications than any other framework.
https://laravel.com/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.