PHPackages                             kiendaotac/laravel-package-tools - 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. kiendaotac/laravel-package-tools

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

kiendaotac/laravel-package-tools
================================

Tools for creating Laravel packages in my CMS

1.4.0(5y ago)07MITPHPPHP ^7.4|^8.0

Since Jan 24Pushed 5y agoCompare

[ Source](https://github.com/kiendaotac/laravel-package-tools)[ Packagist](https://packagist.org/packages/kiendaotac/laravel-package-tools)[ Docs](https://github.com/spatie/laravel-package-tools)[ GitHub Sponsors](https://github.com/spatie)[ RSS](/packages/kiendaotac-laravel-package-tools/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (5)Versions (15)Used By (0)

Tools for creating Laravel packages
===================================

[](#tools-for-creating-laravel-packages)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ca6b11789d1a89361b7434a51aa207df98a92552fdea6d41bcfa50f6c9489c50/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f6c61726176656c2d7061636b6167652d746f6f6c732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-package-tools)[![Tests](https://github.com/spatie/laravel-package-tools/workflows/Tests/badge.svg)](https://github.com/spatie/laravel-package-tools/workflows/Tests/badge.svg)[![Total Downloads](https://camo.githubusercontent.com/622107fb2f3556fbb0b98fdda87867a05f234ced0a54d4c5dd525155ce4cfea0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f6c61726176656c2d7061636b6167652d746f6f6c732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-package-tools)

This package contains a `PackageServiceProvider` that you can use in your packages to easily register config files, migrations, and more.

Here's an example of how it can be used.

```
use Spatie\LaravelPackageTools\PackageServiceProvider;
use Spatie\LaravelPackageTools\Package;

class YourPackageServiceProvider extends PackageServiceProvider
{
    public function configurePackage(Package $package): void
    {
        $package
            ->name('your-package-name')
            ->hasConfigFile()
            ->hasViews()
            ->hasTranslations()
            ->hasAssets()
            ->hasRoute('web')
            ->hasMigration('create_package_tables')
            ->hasCommand(YourCoolPackageCommand::class);
    }
}
```

Under the hood it will do the necessary work to register the necessary things and make all sorts of files publishable.

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/362cb51f7a4c462d27c8445dcab53e98821404ada8d5b265e68299381cbc13c2/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f6c61726176656c2d7061636b6167652d746f6f6c732e6a70673f743d31)](https://spatie.be/github-ad-click/laravel-package-tools)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

Getting started
---------------

[](#getting-started)

This package is opinionated on how you should structure your package. To get started easily, consider using [our package-skeleton repo](https://github.com/spatie/package-skeleton-laravel) to start your package. The skeleton is structured perfectly to work perfectly with the `PackageServiceProvider` in this package.

Usage
-----

[](#usage)

In your package you should let your service provider extend `Spatie\LaravelPackageTools\PackageServiceProvider`.

```
use Spatie\LaravelPackageTools\PackageServiceProvider;
use Spatie\LaravelPackageTools\Package;

class YourPackageServiceProvider extends PackageServiceProvider
{
    public function configurePackage(Package $package) : void
    {
        $package->name('your-package-name');
    }
}
```

Passing the package name to `name` is mandatory.

### Working with a config file

[](#working-with-a-config-file)

To register a config file, you should create a php file with your package name in the `config` directory of your package. In this example it should be at `/config/your-package-name.php`.

If your package name starts with `laravel-`, we expect that your config file does not contain that prefix. So if your package name is `laravel-cool-package`, the config file should be named `cool-package.php`.

To register that config file, call `hasConfigFile()` on `$package` in the `configurePackage` method.

```
$package
    ->name('your-package-name')
    ->hasConfigFile();
```

The `hasConfigFile` method will also make the config file publishable. Users of your package will be able to publish the config file with this command.

```
php artisan vendor:publish --tag=your-package-name-config
```

### Working with views

[](#working-with-views)

Any views your package provides, should be placed in the `/resources/views` directory.

You can register these views with the `hasViews` command.

```
$package
    ->name('your-package-name')
    ->hasViews();
```

This will register your views with Laravel.

If you have a view `/resources/views/myView.blade.php`, you can use it like this: `view('your-package-name::myView')`. Of course, you can also use subdirectories to organise your views. A view located at `/resources/views/subdirectory/myOtherView.blade.php` can be used with `view('your-package-name::subdirectory.myOtherView')`.

Calling `hasViews` will also make views publishable. Users of your package will be able to publish the views with this command:

```
php artisan vendor:publish --tag=your-package-name-views
```

### Working with translations

[](#working-with-translations)

Any translations your package provides, should be placed in the `/resources/lang/` directory.

You can register these translations with the `hasTranslations` command.

```
$package
    ->name('your-package-name')
    ->hasTranslations();
```

This will register the translations with Laravel.

Assuming you save this translation file at `/resources/lang/en/translations.php`...

```
