khsing / laravel-world

provide countries, states, and cities relations and database.
MIT License
431 stars 90 forks source link

Fix init not working on Laravel 8 #40

Closed mokhosh closed 3 years ago

mokhosh commented 3 years ago

I haven't checked if this package inits fine on previous versions, but it had some inconsistencies anyway. Here's what have been fixed:

This fixes https://github.com/khsing/laravel-world/issues/39

Human018 commented 3 years ago

Hi @mokhosh.

Since L8 does allow us to provide namespaces for the seeders, there is probably little reason to publish them. We can now just run the seeds directly from the package.

You could change the namespace to Khsing\World\Database\Seeders

And change the init command to call the full class name $this->call('db:seed',["--class"=>"Khsing\World\Database\Seeders\WorldTablesSeeder"]);

I was going to submit a pull request myself for that sort of change, but since you have already done something similar I though I would suggest it to you instead.

Unless you feel there is a reason the seeders should still be published to each project?

mokhosh commented 3 years ago

Good point. I'd be happy either way. But still there is the problem in WorldTablesSeeder where DB is not imported, right?

Human018 commented 3 years ago

I haven't tested it, but since DB is registered as an Alias in Laravel config/app I imagine it should just work without needing to import it. If not just calling it as\DB should do the job.

charliex311 commented 3 years ago

I have solved the issue. There is a problem within the WorldServiceProvider, where the folders created in the database/ are not following the Laravel conventions. So just change the folder name from seeds to seeders from /database/seeds to /database/seeders solved the problem which is the default convention for laravel.

charliex311 commented 3 years ago

Please merge this PR.

pishguy commented 3 years ago

+1

pishguy commented 3 years ago

not working yet, is package updated for using composer by owner?

   Illuminate\Contracts\Container\BindingResolutionException 

  Target class [Database\Seeders\WorldTablesSeeder] does not exist.
mokhosh commented 3 years ago

Just checked with a fresh Laravel 8 installation and seems to be working. Are you doing these steps in order?

composer require khsing/world
php artisan vendor:publish --force --provider="Khsing\World\WorldServiceProvider"
composer dump-autoload
php artisan world:init
pishguy commented 3 years ago

@mokhosh Yes, i did all of commands as you pasted in comment, i get error again

khsing commented 3 years ago

@MahdiPishguy after composer dump-autoload, you can check your autoloader files grep WorldTablesSeeder vendor/composer/*, if no WorldTablesSeeder, I think seeders files do not published.