Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly install package in Laravel?

Recently, I installed the a package LaravelFacebookSdk.


Install

I update my composer.json by adding

"sammyk/laravel-facebook-sdk": "~3.0"

Then, I run composer update


Service Provider

In my /config/app.php, I add the LaravelFacebookSdkServiceProvider to the providers array.

'providers' => [
    SammyK\LaravelFacebookSdk\LaravelFacebookSdkServiceProvider::class,
    ];

Everything works great. Then, I pushed it to my repository.


Here comes the issue !

Second developer coming in did a git pull and run composer update

He will get an error

 SammyK\LaravelFacebookSdk\LaravelFacebookSdkServiceProvider::class,

is undefine. because, I declared that in my /config/app.php under my providers array.

He have to go comment out that line, and run the composer update first. After everything successfully installed, then go back in and uncomment that line back again.

Will other developer have to do this each time, we installed a new package ?

Am I missing something here ?

Please kindly advise if I did anything wrong.

like image 680
code-8 Avatar asked Jan 11 '16 16:01

code-8


1 Answers

The problem here is that there is a php artisan clear-compiled command being configured to run before the update process in your composer.json file. And since artisan is an integral part of the Laravel app, it will complain when there's something wrong with the app code. Since you have a reference to a class that is not yet present, it will spit out that RuntimeException. You can fix that by moving that command from the pre-update-cmd list to post-update-cmd list in your composer.json.

So change this:

"scripts": {
    ...
    "pre-update-cmd": [
        "php artisan clear-compiled"
    ],
    "post-update-cmd": [
        "php artisan optimize"
    ]
},

To this:

"scripts": {
    ...
    "pre-update-cmd": [
    ],
    "post-update-cmd": [
        "php artisan clear-compiled",
        "php artisan optimize"
    ]
},

Now the clear-compiled command will be run after the update process, when the referenced LaravelFacebookSdkServiceProvider class is present, so no more errors.

like image 165
Bogdan Avatar answered Oct 20 '22 07:10

Bogdan