PHP code example of onlinepets / laravel-conditional-migrations

1. Go to this page and download the library: Download onlinepets/laravel-conditional-migrations library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

onlinepets / laravel-conditional-migrations example snippets


'providers' => [
    // ...
    Onlinepets\ConditionalMigrations\ServiceProvider::class,
];

use Onlinepets\ConditionalMigrations\Contracts\ConditionalMigration;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Carbon;

class DoSomethingVeryIntensive extends Migration implements ConditionalMigration
{
    public function up()
    {
        Schema::table('users', function (Blueprint $table) {
            //
        });
    }

    public function down()
    {
        Schema::table('users', function (Blueprint $table) {
            //
        });
    }

    public function shouldRun(): bool
    {
        return (new Carbon('1 AM'))->lessThan(now())
            && (new Carbon('2 AM'))->greaterThan(now());
    }
}

return [
    
    'always_run' => env('APP_DEBUG', false),
    
];

return [

    'always_run' => function (): bool {
        // calculate whether it should run
    },

];
bash
$ php artisan vendor:publish --provider="Onlinepets\ConditionalMigrations\ServiceProvider"