Publishing of migration and config file not working?
I simply followed the guide for installation at
https://docs.beyondco.de/laravel-websockets/1.0/getting-started/installation.html
and the files are only published in the vendor folder. Hence, php artisan migrate does not find any new migrations, because it is not in Laravels database folder. The config also only stays in the vendor dictionary and doesn't get copied into Laravels config folder. Is this behaviour correct?
If so it should definitely be mentioned that you need to copy/paste the files first before running php artisan migrate.
thanks!
Have you tried to execute the following commands?
For the migrations file to appear in your Laravel project database/migrations folder:
php artisan vendor:publish --provider="BeyondCode\LaravelWebSockets\WebSocketsServiceProvider" --tag="migrations"
For the configuration file to appear in your Laravel project config folder:
php artisan vendor:publish --provider="BeyondCode\LaravelWebSockets\WebSocketsServiceProvider" --tag="config"
@andresayej Yes, I executed the commands and I get the response "Publishing complete.". However, they don't appear in said Laravel dictionaries.
Please do provide more details as:
- OS
- Laravel version
- Contents in laravel.log related to BeyondCode\LaravelWebSockets
Do you have write permissions for the directories: database, database/migrations, config
@andresayej
- MacOS Mojave
- Just updated to 5.7 from 5.4->5.5->5.6
- Cant find any related logs
I do have write permissions for all of those.
It sounds to me that somehow the ServiceProvider is not automatically registered (present) in your application, thus not executing the commands, which live there.
Try adding the service provider manually in your config/app.php:
'providers' => [
// ...
BeyondCode\LaravelWebSockets\WebSocketsServiceProvider::class,
];
@andresayej that's it! You're right. Now the question is why it was missing in the first place? Any idea?
Thanks a lot mate! :)
Great to hear it works!
My best guess is that because of all the upgrades you've accomplished, composer was in need of a composer dump-autoload execution as to properly reinitialize all the stuff needed.
To validate this theory if your terminal history is still present after you executed:
composer require beyondcode/laravel-websockets
check if in a response similar to this:
> Writing lock file
> Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
> Discovered Package: beyondcode/laravel-dump-server
> Discovered Package: beyondcode/laravel-websockets
> Discovered Package: fideloper/proxy
> Discovered Package: laravel/tinker
> Discovered Package: nesbot/carbon
> Discovered Package: nunomaduro/collision
> Package manifest generated successfully.
The one: Discovered Package: beyondcode/laravel-websockets exists.
@andresayej
Unfortunately, the console history is gone (shoutout to PHPStorm 🙄). When do you recommend to run composer dump-autoload to avoid similar problems in the future? Thank you!
Well in abstract a composer dump-autoload should be executed when a Class has been added or changed and it is not part of the autoload -> classmap definitions located in your composer.json file.
The command regenerates the list of all classes that need to be included in the project (autoload_classmap.php)
In most of my cases i use it after a migration generation and/or change.
In your case it's very hard to determine if the command is really needed, however note that it doesn't cost you anything to run it for example after a composer update (and/or Laravel upgrade).That being said the benefit would be that it will save you a lot of time in troubleshooting if perhaps some class is not loaded, but you are certain it exists.
Mu rule of thumb:
- After composer update i run a
composer dump-autoload - If any migrations classes problems occur, the first debugging action is to run a
composer dump-autoload - If for a package the Service Provider (which is a Class) doesn't get automatically registered then the first debugging action is to run a
composer dump-autoload, then i try to register it manually.
You have mentioned that the upgrade has started from a 5.4 laravel version (this version doesn't support the Auto-Discovery feature, the feature is present from Laravel 5.5 forward - more from Taylor himself: https://medium.com/@taylorotwell/package-auto-discovery-in-laravel-5-5-ea9e3ab20518 ). In the link Taylor describes that this feature also leverages composer to do the magic behind the Auto-Discovery and because of that i would assume that the composer.json which was in your 5.4 project is different from the one which comes with a fresh 5.5 install. So to align the missing stuff (including any new required stuff to autoload) of the 5.4 composer.json and 5.5+ composer.json from an upgrade to upgrade basis a composer dump-autoload would do just that - align the missing stuff. This peculiarity with a not aligned (not updated) composer.json, however mostly applies to existing(old) projects which are being upgraded and not for fresh installs.
I hope this information is useful.
An important note:
To invoke a Auto-Discovery, Laravel uses the composer scripts located in your composer.json:
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi"
]
}
As stated here: https://getcomposer.org/doc/articles/scripts.md post-autoload-dump - occurs after the autoloader has been dumped, either during install/update, or via the dump-autoload command
So a typical procedure if this exists in your scripts within composer.json will be:
You have an application and within it a composer install OR composer update OR composer require ... OR composer dump-autoload command occurs, then it invokes the post-autoload-dump which houses the command @php artisan package:discover --ansi which itself is responsible to do the Auto-Discovery on/after every new package downloaded (required).
This is what is needed to ensure that in the future if you install a package that has an Auto-Discovery feature, it will auto-register because Laravel will try to find it with the artisan command: php artisan package:discover --ansi. Alternatively you can run the command manually after every new package download.
Can you share your composer.json?
is it possible to run it with laravel 5.5?
@jadavpalak sure, why not?
I mean I have project with laravel 5.5 and i don't want to update the version but in docs it is mention that "Laravel WebSockets is a package for Laravel 5.7 and up" https://docs.beyondco.de/laravel-websockets/1.0/getting-started/introduction.html
So could you suggest me which version of WebSockets will be suitable for laravel 5.5
I had an issue with the cache of the config.
  ipnttools1  iaskakho  …  sites  htdocs  ipnttools  art config:clear Configuration cache cleared!   ipnttools1  iaskakho  …  sites  htdocs  ipnttools  art route:clear Route cache cleared!   ipnttools1  iaskakho  …  sites  htdocs  ipnttools  art view:clear Compiled views cleared!   ipnttools1  iaskakho  …  sites  htdocs  ipnttools  art cache:clear Application cache cleared!   ipnttools1  iaskakho  …  sites  htdocs  ipnttools  art websockets:serve Starting the WebSocket server on port 6001...