1. Go to this page and download the library: Download kstmostofa/laravel-backfill 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/ */
kstmostofa / laravel-backfill example snippets
namespace App\Backfills;
use App\Models\User;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Str;
use Kstmostofa\Backfill\Backfill;
class BackfillUserSlugs extends Backfill
{
public int $batchSize = 1000;
public int $sleepMs = 100;
public function collection(): Builder
{
return User::query()->whereNull('slug');
}
public function process($record): void
{
$record->update(['slug' => Str::slug($record->name)]);
}
}
public bool $ledger = true;
public bool $externalSideEffects = true;
public function tenants(): ?iterable
{
return Tenant::query()->pluck('id');
}
public function useTenant(string|int $tenant): void
{
Tenant::find($tenant)->makeCurrent();
}