PHPackages                             geeksceo/laravel-project-builder - 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. [Framework](/categories/framework)
4. /
5. geeksceo/laravel-project-builder

AbandonedLibrary[Framework](/categories/framework)

geeksceo/laravel-project-builder
================================

Build usualy a Laravel project

1.x-dev(1y ago)053MITPHP

Since Feb 24Pushed 1y ago1 watchersCompare

[ Source](https://github.com/oowasn/laravel-project-builder)[ Packagist](https://packagist.org/packages/geeksceo/laravel-project-builder)[ RSS](/packages/geeksceo-laravel-project-builder/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (2)Used By (0)

Laravel Project Builder
=======================

[](#laravel-project-builder)

[![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 `InitServiceProvider` 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 Illuminate\Support\ServiceProvider;
use ZDSLab\Init\Console\InitProject;

class InitServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot() {
        // Register the command if we are using the application via the CLI
        if ($this->app->runningInConsole()) {
            $this->commands([
                InitProject::class
            ]);

            // config file
            $this->publishes([
                __DIR__.'/../config/config.php' => config_path('init.php'),
              ], 'config'
            );
        }

        $this->loadMigrationsFrom(__DIR__ . '/../database/migrations');

        // $this->loadRoutesFrom(__DIR__.'/../routes/web.php');
        // $this->loadViewsFrom(__DIR__.'/../resources/views', 'init');
    }

    public function register() {
        $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'init');
        /* $this->registerPublishables();
        $this->loadHelpers(); */
    }

    private function registerPublishables()
    {
        /* $publishablePath = dirname(__DIR__).'/publishable';

        $publishable = [
            'login-assets' => [
                "{$publishablePath}/login-assets/" => app_path('public'),
            ]
        ];

        foreach ($publishable as $group => $paths) {
            $this->publishes($paths, $group);
        } */
    }

    protected function loadHelpers()
    {
        /* foreach (glob(__DIR__.'/Helpers/*.php') as $filename) {
            require_once $filename;
        } */
    }
}
```

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

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

[](#getting-started)

This package is opinionated on how you can build your Laravel project with our implementation.

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

Should your package have multiple config files, you can pass their names as an array to `hasConfigFile`

```
$package
    ->name('your-package-name')
    ->hasConfigFile(['my-config-file', 'another-config-file']);
```

### 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')`.

#### Using a custom view namespace

[](#using-a-custom-view-namespace)

You can pass a custom view namespace to the `hasViews` method.

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

You can now use the views of the package like this:

```
view('custom-view-namespace::myView');
```

#### Publishing the views

[](#publishing-the-views)

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

> **Note:**
>
> If you use custom view namespace then you should change your publish command like this:

```
php artisan vendor:publish --tag=custom-view-namespace-views
```

### Sharing global data with views

[](#sharing-global-data-with-views)

You can share data with all views using the `sharesDataWithAllViews` method. This will make the shared variable available to all views.

```
$package
    ->name('your-package-name')
    ->sharesDataWithAllViews('companyName', 'Spatie');
```

### Working with Blade view components

[](#working-with-blade-view-components)

Any Blade view components that your package provides should be placed in the `/src/Components` directory.

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

```
$package
    ->name('your-package-name')
    ->hasViewComponents('spatie', Alert::class);
```

This will register your view components with Laravel. In the case of `Alert::class`, it can be referenced in views as ``, where `spatie` is the prefix you provided during registration.

Calling `hasViewComponents` will also make view components publishable, and will be published to `app/Views/Components/vendor/`.

Users of your package will be able to publish the view components with this command:

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

### Working with view composers

[](#working-with-view-composers)

You can register any view composers that your project uses with the `hasViewComposers` method. You may also register a callback that receives a `$view` argument instead of a classname.

To register a view composer with all views, use an asterisk as the view name `'*'`.

```
$package
    ->name('your-package-name')
    ->hasViewComposer('viewName', MyViewComposer::class)
    ->hasViewComposer('*', function($view) {
        $view->with('sharedVariable', 123);
    });
```

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

```
return [
    'translatable' => 'translation',
];
```

... your package and users will be able to retrieve the translation with:

```
trans('your-package-name::translations.translatable'); // returns 'translation'
```

If your package name starts with `laravel-` then you should leave that off in the example above.

Coding with translation strings as keys, you should create JSON files in `/resources/lang/.json`.

For example, creating `/resources/lang/it.json` file like so:

```
{
    "Hello!": "Ciao!"
}
```

...the output of...

```
trans('Hello!');
```

...will be `Ciao!` if the application uses the Italian language.

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

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

### Working with assets

[](#working-with-assets)

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

You can make these assets publishable the `hasAssets` method.

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

Users of your package will be able to publish the assets with this command:

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

This will copy over the assets to the `public/vendor/` directory in the app where your package is installed in.

### Working with migrations

[](#working-with-migrations)

The `PackageServiceProvider` assumes that any migrations are placed in this directory: `/database/migrations`. Inside that directory you can put any migrations.

To register your migration, you should pass its name without the extension to the `hasMigration` table.

If your migration file is called `create_my_package_tables.php.stub` you can register them like this:

```
$package
    ->name('your-package-name')
    ->hasMigration('create_my_package_tables');
```

Should your package contain multiple migration files, you can just call `hasMigration` multiple times or use `hasMigrations`.

```
$package
    ->name('your-package-name')
    ->hasMigrations(['my_package_tables', 'some_other_migration']);
```

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

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

Like you might expect, published migration files will be prefixed with the current datetime.

You can also enable the migrations to be registered without needing the users of your package to publish them:

```
$package
    ->name('your-package-name')
    ->hasMigrations(['my_package_tables', 'some_other_migration'])
    ->runsMigrations();
```

### Working with a publishable service provider

[](#working-with-a-publishable-service-provider)

Some packages need an example service provider to be copied into the `app\Providers` directory of the Laravel app. Think of for instance, the `laravel/horizon` package that copies an `HorizonServiceProvider` into your app with some sensible defaults.

```
$package
    ->name('your-package-name')
    ->publishesServiceProvider($nameOfYourServiceProvider);
```

The file that will be copied to the app should be stored in your package in `/resources/stubs/{$nameOfYourServiceProvider}.php.stub`.

When your package is installed into an app, running this command...

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

... will copy `/resources/stubs/{$nameOfYourServiceProvider}.php.stub` in your package to `app/Providers/{$nameOfYourServiceProvider}.php` in the app of the user.

### Registering commands

[](#registering-commands)

You can register any command you package provides with the `hasCommand` function.

```
$package
    ->name('your-package-name')
    ->hasCommand(YourCoolPackageCommand::class);
```

If your package provides multiple commands, you can either use `hasCommand` multiple times, or pass an array to `hasCommands`

```
$package
    ->name('your-package-name')
    ->hasCommands([
        YourCoolPackageCommand::class,
        YourOtherCoolPackageCommand::class,
    ]);
```

### Adding an installer command

[](#adding-an-installer-command)

Instead of letting your users manually publishing config files, migrations, and other files manually, you could opt to add an install command that does all this work in one go. Packages like Laravel Horizon and Livewire provide such commands.

When using Laravel Package Tools, you don't have to write an `InstallCommand` yourself. Instead, you can simply call, `hasInstallCommand` and configure it using a closure. Here's an example.

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

class YourPackageServiceProvider extends PackageServiceProvider
{
    public function configurePackage(Package $package): void
    {
        $package
            ->name('your-package-name')
            ->hasConfigFile()
            ->hasMigration('create_package_tables')
            ->publishesServiceProvider('MyServiceProviderName')
            ->hasInstallCommand(function(InstallCommand $command) {
                $command
                    ->publishConfigFile()
                    ->publishMigrations()
                    ->askToRunMigrations()
                    ->copyAndRegisterServiceProviderInApp()
                    ->askToStarRepoOnGitHub('your-vendor/your-repo-name')
            });
    }
}
```

With this in place, the package user can call this command:

```
php artisan your-package-name:install
```

Using the code above, that command will:

- publish the config file
- publish the migrations
- copy the `/resources/stubs/MyProviderName.php.stub` from your package to `app/Providers/MyServiceProviderName.php`, and also register that provider in `config/app.php`
- ask if migrations should be run now
- prompt the user to open up `https://github.com/'your-vendor/your-repo-name'` in the browser in order to star it

You can also call `startWith` and `endWith` on the `InstallCommand`. They will respectively be executed at the start and end when running `php artisan your-package-name:install`. You can use this to perform extra work or display extra output.

```
use use Spatie\LaravelPackageTools\Commands\InstallCommand;

public function configurePackage(Package $package): void
{
    $package
        // ... configure package
        ->hasInstallCommand(function(InstallCommand $command) {
            $command
                ->startWith(function(InstallCommand $command) {
                    $command->info('Hello, and welcome to my great new package!')
                })
                ->publishConfigFile()
                ->publishMigrations()
               ->askToRunMigrations()
                ->copyAndRegisterServiceProviderInApp()
                ->askToStarRepoOnGitHub('your-vendor/your-repo-name')
                ->endWith(function(InstallCommand $command) {
                    $command->info('Have a great day!');
                })
        });
}
```

### Working with routes

[](#working-with-routes)

The `PackageServiceProvider` assumes that any route files are placed in this directory: `/routes`. Inside that directory you can put any route files.

To register your route, you should pass its name without the extension to the `hasRoute` method.

If your route file is called `web.php` you can register them like this:

```
$package
    ->name('your-package-name')
    ->hasRoute('web');
```

Should your package contain multiple route files, you can just call `hasRoute` multiple times or use `hasRoutes`.

```
$package
    ->name('your-package-name')
    ->hasRoutes(['web', 'admin']);
```

### Using lifecycle hooks

[](#using-lifecycle-hooks)

You can put any custom logic your package needs while starting up in one of these methods:

- `registeringPackage`: will be called at the start of the `register` method of `PackageServiceProvider`
- `packageRegistered`: will be called at the end of the `register` method of `PackageServiceProvider`
- `bootingPackage`: will be called at the start of the `boot` method of `PackageServiceProvider`
- `packageBooted`: will be called at the end of the `boot` method of `PackageServiceProvider`

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Freek Van der Herten](https://github.com/freekmurze)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance44

Moderate activity, may be stable

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity23

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

439d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b080b19cb61d6b7421517bdd60030d6ec6b8557fb54704be05b9dbae4ce852e6?d=identicon)[oowasn](/maintainers/oowasn)

---

Top Contributors

[![oowasn](https://avatars.githubusercontent.com/u/89300034?v=4)](https://github.com/oowasn "oowasn (68 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/geeksceo-laravel-project-builder/health.svg)

```
[![Health](https://phpackages.com/badges/geeksceo-laravel-project-builder/health.svg)](https://phpackages.com/packages/geeksceo-laravel-project-builder)
```

###  Alternatives

[laravel/telescope

An elegant debug assistant for the Laravel framework.

5.2k67.8M191](/packages/laravel-telescope)[spiral/roadrunner

RoadRunner: High-performance PHP application server and process manager written in Go and powered with plugins

8.4k12.2M84](/packages/spiral-roadrunner)[nolimits4web/swiper

Most modern mobile touch slider and framework with hardware accelerated transitions

41.8k177.2k1](/packages/nolimits4web-swiper)[laravel/prompts

Add beautiful and user-friendly forms to your command-line applications.

708181.8M592](/packages/laravel-prompts)[cakephp/chronos

A simple API extension for DateTime.

1.4k47.7M121](/packages/cakephp-chronos)[laravel/pail

Easily delve into your Laravel application's log files directly from the command line.

91245.3M586](/packages/laravel-pail)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
