PHPackages                             mvalim/package-utils - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. mvalim/package-utils

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mvalim/package-utils
====================

Some helpers for Laravel 5 package development

61.7kPHP

Since Jan 24Pushed 11y ago1 watchersCompare

[ Source](https://github.com/mvalim/package-utils)[ Packagist](https://packagist.org/packages/mvalim/package-utils)[ RSS](/packages/mvalim-package-utils/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel 5 Package Utils
=======================

[](#laravel-5-package-utils)

Since laravel 5 doesn't ship with some of the workbench/package functionalities I've decided to write this package and add some common capabilities to the default service provider, like publishing *configs* and *migrations*

If you need the old functionaties back you can try:

**Configuration:**

Usage
-----

[](#usage)

To use this helpers the first step is to add this package to the composer dependencies.

```
composer require mvalim/package-utils

```

After the package was installed you only need to extend `Mvalim\PackageUtils\Provider`in your service provider instead of `Illuminate\Support\ServiceProvider` and the helpers will be available.

Once you have installed this package you can register as many packages as you want without worrying about performance. The publishers will only register your resources at runtime, no additional checks (like if files exist) will be made. If the resources were not yet published an exception can be thrown.

First you must define your package name and namespace (for config, and other resources that need a namespace). When regitering your package just call:

```
$this->package('/', '');

ex.: $this->package('mvalim/package', 'my-package');

```

**Warning:** *If no namespace is provided, the `vendor.packageName` will be used as the namespace*

Methods available
-----------------

[](#methods-available)

When you extend the `Provider` class the below methods will be available:

#### needsConfig($path)

[](#needsconfigpath)

Add configuration files to be published.

**$path**: can be a single file or a directory with multiple files that will be merged in a single `config///config.php` when published.

**Warging:** Like the default laravel config files, all these files must return an array.

#### needsMigration($path)

[](#needsmigrationpath)

Add migration files to be published. **$path**: must be a directory containing all the migrations that needs to be published to the migrations path.

**Warning:** This helper will **only copy** the files to the migrations path.

Publishing your resources
-------------------------

[](#publishing-your-resources)

After you've defined your package resources you can publish them using the folowing command:

```
php artisan package:publish

php artisan package:publish mvalim/package

// publish only the configs
php artisan package:publish mvalim/package config

// backup the existing, and overwrite the resources
php artisan package:publish mvalim/package --force

```

If you don't provide a resource, all of the registered resources will be published. The `package:publish` command accept the option `--force` that will backup the existing resources to `storage/packages` and will override them.

Service provider example
------------------------

[](#service-provider-example)

```
