1. Go to this page and download the library: Download mll-lab/laravel-utils 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/ */
mll-lab / laravel-utils example snippets
use MLL\LaravelUtils\Database\Autoincrement;
final class MaxFooId extends Autoincrement
{
public static function name(): string
{
return 'max_foo_id';
}
}
public function up() {
MaxFooId::createTable();
}
public $incrementing = false;
protected static function booted(): void
{
self::creating(function (self $instance): void {
$instance->id ??= MaxFooId::next();
});
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Carbon;
use MLL\LaravelUtils\Database\ConditionalMigration
return new class extends Migration implements ConditionalMigration {
public function up(): void
{
// Something that would put intense strain on the database
}
public function shouldRun(): bool
{
$currentHour = Carbon::now()->hour;
// Only run between 01:00 and 03:00
return $currentHour > 1 && $currentHour < 3;
}
};