feat: initial commit
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ClientResource\RelationManagers;
|
||||
|
||||
use App\DataObjects\CreateBranchDTO;
|
||||
use App\Processes\Branch\CreateBranchProcess;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Support\RawJs;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class BranchesRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'branches';
|
||||
|
||||
protected static bool $shouldCheckPolicyExistence = true;
|
||||
|
||||
protected CreateBranchProcess $createBranchProcess;
|
||||
public function __construct() {
|
||||
$this->createBranchProcess = new CreateBranchProcess();
|
||||
}
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('code')->required()->unique('branches','code'),
|
||||
Forms\Components\TextInput::make('series')->label('Current Series')
|
||||
->required()
|
||||
->numeric()
|
||||
->integer()
|
||||
->maxLength(6)
|
||||
->minLength(1)
|
||||
->mask(RawJs::make(<<<'JS'
|
||||
'999999'
|
||||
JS))
|
||||
])->columns(1);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->recordTitleAttribute('client_id')
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('code')->label('Branch Code'),
|
||||
Tables\Columns\TextColumn::make('current_series')->label('Current Series'),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->headerActions([
|
||||
Tables\Actions\CreateAction::make()
|
||||
->mutateFormDataUsing(function (array $data): array {
|
||||
$data['client_id'] = $this->ownerRecord->id;
|
||||
return $data;
|
||||
})
|
||||
->using(function($data) {
|
||||
$payload = new CreateBranchDTO(data: $data);
|
||||
return $this->createBranchProcess->run($payload)->branch;
|
||||
}),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user