PHP code example of codewithdennis / filament-factory-action

1. Go to this page and download the library: Download codewithdennis/filament-factory-action 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/ */

    

codewithdennis / filament-factory-action example snippets


class ProfileFactory extends Factory
{
    public function definition(): array
    {
        return [
            'name' => fake()->company(),
            'is_public' => rand(0, 1),
        ];
    }
}

FactoryAction::make(),

use App\Filament\Resources\ProfileResource;
use CodeWithDennis\FactoryAction\FactoryAction;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;

class ListProfiles extends ListRecords
{
    protected static string $resource = ProfileResource::class;

    protected function getHeaderActions(): array
    {
        return [
            FactoryAction::make()
                ->color('danger')
                // ->slideOver()
                ->icon('heroicon-o-wrench'),
            Actions\CreateAction::make()
        ];
    }
}

protected function getHeaderActions(): array
{
    return [
        FactoryAction::make()
            // If you want to create or create and attach you can do so using `hasMany`
            ->hasMany([Badge::class, Category::class])
            // If you want to attach existing models you can do so using `belongsToMany`
            ->belongsToMany([Badge::class, Category::class]),
    ];
}

->hidden(fn() => false)