laravel-websockets icon indicating copy to clipboard operation
laravel-websockets copied to clipboard

Publishing of migration and config file not working?

Open cowera opened this issue 7 years ago • 14 comments

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!

cowera avatar Jun 17 '19 12:06 cowera

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 avatar Jun 17 '19 12:06 andresayej

@andresayej Yes, I executed the commands and I get the response "Publishing complete.". However, they don't appear in said Laravel dictionaries.

cowera avatar Jun 17 '19 12:06 cowera

Please do provide more details as:

  1. OS
  2. Laravel version
  3. Contents in laravel.log related to BeyondCode\LaravelWebSockets

Do you have write permissions for the directories: database, database/migrations, config

andresayej avatar Jun 17 '19 12:06 andresayej

@andresayej

  1. MacOS Mojave
  2. Just updated to 5.7 from 5.4->5.5->5.6
  3. Cant find any related logs

I do have write permissions for all of those.

cowera avatar Jun 17 '19 12:06 cowera

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 avatar Jun 17 '19 13:06 andresayej

@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! :)

cowera avatar Jun 17 '19 13:06 cowera

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 avatar Jun 17 '19 13:06 andresayej

@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!

cowera avatar Jun 17 '19 13:06 cowera

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:

  1. After composer update i run a composer dump-autoload
  2. If any migrations classes problems occur, the first debugging action is to run a composer dump-autoload
  3. 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.

andresayej avatar Jun 17 '19 14:06 andresayej

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?

andresayej avatar Jun 17 '19 15:06 andresayej

is it possible to run it with laravel 5.5?

jadavpalak avatar Jan 13 '20 18:01 jadavpalak

@jadavpalak sure, why not?

cowera avatar Jan 14 '20 07:01 cowera

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

jadavpalak avatar Jan 16 '20 10:01 jadavpalak

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...

igor-astsakhov avatar Nov 06 '23 11:11 igor-astsakhov