bnbwebexpertise / laravel-attachments

Laravel 5.4+ file attachment helpers
87 stars 28 forks source link

Ignore migrations #34

Open quentin-tdclic opened 2 years ago

quentin-tdclic commented 2 years ago

Hello,

I'm using Tenancy and I have a problem with your migrations. When I do a "artisan migrate:fresh", I don't want your migrations to automatically be run (because I want them for each Tenant, not for the "central app").

Can you do something so we can :

Laravel Sanctum does it very well : https://laravel.com/docs/9.x/sanctum#migration-customization

Thanks !

quentin-tdclic commented 2 years ago

I have a suggestion : in bnbwebexpertise\laravel-attachments\src\AttachmentsServiceProvider.php

class AttachmentsServiceProvider extends ServiceProvider
{
    /**
     * Indicates if Attachments' migrations will be run.
     *
     * @var bool
     */
    public static $runsMigrations = true;

    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {
        (...)

        if (self::shouldRunMigrations()) {
            $this->loadMigrationsFrom(__DIR__ . '/../migrations');
        }

        (...)
    }

    (...)

    /**
     * Determine if Attachments' migrations should be run.
     *
     * @return bool
     */
    public static function shouldRunMigrations()
    {
        return static::$runsMigrations;
    }

    /**
     * Configure Attachments to not register its migrations.
     *
     * @return static
     */
    public static function ignoreMigrations()
    {
        static::$runsMigrations = false;
    }
}

Usage : in app\Providers\AppServiceProvider.php

use Bnb\Laravel\Attachments\AttachmentsServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    (...)

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        AttachmentsServiceProvider::ignoreMigrations();
    }
}