sakanjo/filament-fakefill-action

A filament action to fill the form with fake data.

v1.0.0 2024-05-04 10:34 UTC

This package is auto-updated.

Last update: 2024-10-20 19:46:16 UTC


README

Workflow status Laravel v11.x PHP 8.2

A Filament action to fake fill the form state.

✨ Help support the maintenance of this package by sponsoring me.

Preview

Table of Contents

đŸ“Ļ Install

composer require sakanjo/filament-fakefill-action

đŸĻ„ Usage

On the create page

<?php

namespace App\Filament\Admin\Resources\UserResource\Pages;

use App\Filament\Admin\Resources\UserResource;
use Filament\Resources\Pages\CreateRecord;
use SaKanjo\FilamentFakeFillAction\Actions\FakeFillAction;

class CreateUser extends CreateRecord
{
    protected static string $resource = UserResource::class;

    protected function getHeaderActions(): array
    {
        return [
            FakeFillAction::make(),
        ];
    }
}

On the edit page

<?php

namespace App\Filament\Admin\Resources\UserResource\Pages;

use App\Filament\Admin\Resources\UserResource;
use App\Filament\Base\Pages\EditRecord;
use SaKanjo\FilamentFakeFillAction\Actions\FakeFillAction;

class EditUser extends EditRecord
{
    protected static string $resource = UserResource::class;

    protected function getHeaderActions(): array
    {
        return [
            FakeFillAction::make(),
        ];
    }
}

Functions

isFakeFilling

<?php

namespace Database\Factories;

use App\Models\Address;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;

use function SaKanjo\FilamentFakeFillAction\isFakeFilling;

class UserFactory extends Factory
{
    public function definition(): array
    {
        return [
            'name' => isFakeFilling() ? 'Name set from factory' : fake()->name(),
            'email' => fake()->unique()->safeEmail(),
            'email_verified_at' => now(),
            'password' => Hash::make('password'),
            'remember_token' => Str::random(10),
            'address_id' => isFakeFilling() ? Address::query()->inRandomOrder()->first()->getKey() : null,
        ];
    }
}

💖 Support the development

Do you like this project? Support it by donating

Click the "💖 Sponsor" at the top of this repo.

Šī¸ Credits

📄 License

MIT License Š 2023-PRESENT Salah Kanjo