Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon How do I publish the migration and config files for Spatie


How do I publish the migration and config files for Spatie


To publish the migration and config files for a Spatie package in Laravel, you generally use the `php artisan vendor:publish` command targeting the package's service provider. The exact command depends on the specific Spatie package you are using, but the process follows a similar pattern.

For Spatie Laravel Permission package:

1. After installing the package via Composer:
bash
   composer require spatie/laravel-permission
   

2. Publish the migration and config files by running:
bash
   php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider"
   

This command publishes the migration files needed to create the roles and permissions tables, as well as the `config/permission.php` configuration file[3][8].

3. After publishing, run the migrations:

bash
   php artisan migrate
   

4. Clear your config cache if necessary:
bash
   php artisan config:clear
   

For Spatie Laravel Settings package:

1. Install the package:
bash
   composer require spatie/laravel-settings
   

2. Publish the migration files with:
bash
   php artisan vendor:publish --provider="Spatie\LaravelSettings\LaravelSettingsServiceProvider" --tag="migrations"
   

3. Publish the config file separately with:
bash
   php artisan vendor:publish --provider="Spatie\LaravelSettings\LaravelSettingsServiceProvider" --tag="config"
   

4. Run the migrations:
bash
   php artisan migrate
   

For Spatie Laravel Medialibrary package:

1. Install the package:
bash
   composer require spatie/laravel-medialibrary
   

2. Publish the migration for the media table:
bash
   php artisan vendor:publish --provider="Spatie\MediaLibrary\MediaLibraryServiceProvider" --tag="medialibrary-migrations"
   

3. Optionally, publish the config file:
bash
   php artisan vendor:publish --provider="Spatie\MediaLibrary\MediaLibraryServiceProvider" --tag="medialibrary-config"
   

4. Run the migrations:
bash
   php artisan migrate
   

Summary of the process:

- Use `php artisan vendor:publish` with the `--provider` option specifying the Spatie package's service provider class.
- Optionally, use the `--tag` option to publish only migrations or config files if the package supports it.
- Run `php artisan migrate` to apply the migrations.
- Clear config cache if needed with `php artisan config:clear`.

This approach ensures that the package's migration and configuration files are copied into your Laravel application's directories (`database/migrations` and `config/` respectively), allowing you to customize and run them as part of your app setup[3][4][5][6][8].

Citations:
[1] https://spatie.be/videos/laravel-package-training/using-config-files
[2] https://spatie.be/docs/laravel-permission/v6/upgrading
[3] https://spatie.be/docs/laravel-permission/v6/installation-laravel
[4] https://github.com/spatie/laravel-settings
[5] https://spatie.be/docs/laravel-medialibrary/v11/installation-setup
[6] https://packagist.org/packages/spatie/laravel-settings
[7] https://kritimyantra.com/blogs/laravel-12-image-upload-spatie-medialibrary
[8] https://www.honeybadger.io/blog/laravel-permissions-roles/
[9] https://github.com/spatie/laravel-package-tools/blob/main/README.md