Jenssen
Jenssen

Reputation: 1871

Laravel use package in package

I'm developing a package in Laravel 5.5 where I need this package:

https://github.com/laracasts/PHP-Vars-To-Js-Transformer

The problem is that It's not registering for some reason. When I dd in the JavaScriptServiceProvider.php nothing happens. When I use the Javascript facade I get an error that it does not exists?!

My package composer.json file:

"require": {
        "php" : "^7.0",
        "illuminate/support": "~5.5.0",
        "laracasts/utilities": "^3.0"
    },

I use Laravel 5.5 so it should be registered by default (composer.json from laracasts package):

"extra": {
        "laravel": {
            "providers": [
                "Laracasts\\Utilities\\JavaScript\\JavaScriptServiceProvider"
            ],
            "aliases": {
                "JavaScript": "Laracasts\\Utilities\\JavaScript\\JavaScriptFacade"
            }
        }
    }

What am I doing wrong here?

Upvotes: 1

Views: 2101

Answers (2)

Chandra
Chandra

Reputation: 19

You need to following steps, to solve this issue :

  1. Run the command in your packages directory :

    composer require laracasts/utilities

  2. Now use this in your package (on top of the file) whenever you want to use this dependency:

    use Laracasts\Utilities\JavaScript\yourClassName

Upvotes: 0

Sebastian
Sebastian

Reputation: 928

I faced the same problem using different other packages in my own package.

Here are the steps that worked for me:

  1. Add the required package as a dependency in your own package:

    composer require laracasts/utilities
  2. Update your package in the Laravel project (e.g. by incrementing the version number or by removing your package and reinstalling it.

    composer update # in main Laravel project
  3. Then you should see, that in the main Laravel project there is auto-discovery of your own package and the dependency to laracasts/utilities.

Let me know if this helped you or if I can give more assistance.

Upvotes: 6

Related Questions