F
Filament13mo ago
Quin.

Custom page that's create a record

Hello i am trying to make a custom page that has a form that can create a record for my model. Unfornatly it is not working right now. I can't find the best example on the internet someone can help?
class RequestDomainPage extends Page implements HasForms
{

use InteractsWithForms;

protected static ?string $model = RequestDomain::class;
protected static ?string $navigationIcon = 'heroicon-o-document-text';

protected static string $view = 'filament.pages.request-domain-page';

protected static ?string $title = 'Domein aanvragen';


public $domain;
public $customer_id;


public function mount(): void
{
$this->form->fill();
}

protected function getFormSchema(): array
{
return [
Card::make()->schema([
TextInput::make('domain')
->label('Domain')
->required(),
Select::make('customer_id')
->label('Customer')
->placeholder('Select Customer')
->options(
\App\Models\Customer::all()->pluck('name', 'id')
)
->required(),
])
];
}
protected function getFormActions(): array
{
return [
Action::make('kak')
->label('Submit')
->action(function (RequestDomain $requestDomain) {
RequestDomain::create([
'domain' => $this->domain,
'customer_id' => $this->customer_id
]);
}),
];
}
}
class RequestDomainPage extends Page implements HasForms
{

use InteractsWithForms;

protected static ?string $model = RequestDomain::class;
protected static ?string $navigationIcon = 'heroicon-o-document-text';

protected static string $view = 'filament.pages.request-domain-page';

protected static ?string $title = 'Domein aanvragen';


public $domain;
public $customer_id;


public function mount(): void
{
$this->form->fill();
}

protected function getFormSchema(): array
{
return [
Card::make()->schema([
TextInput::make('domain')
->label('Domain')
->required(),
Select::make('customer_id')
->label('Customer')
->placeholder('Select Customer')
->options(
\App\Models\Customer::all()->pluck('name', 'id')
)
->required(),
])
];
}
protected function getFormActions(): array
{
return [
Action::make('kak')
->label('Submit')
->action(function (RequestDomain $requestDomain) {
RequestDomain::create([
'domain' => $this->domain,
'customer_id' => $this->customer_id
]);
}),
];
}
}
13 Replies
Matthew
Matthew13mo ago
you need to create array $fillable in your model. Ex: $fillable = ["test1","test2",...]. YOu also ned to make a migration containing said columns.
Quin.
Quin.OP13mo ago
Already got all that 🙂
Matthew
Matthew13mo ago
mag ik je blade ff zien? Also, what do you mean it doesnt work? Its not showing, or its not saving?
Quin.
Quin.OP13mo ago
tuurlijk kerel
<x-filament-panels::page>
<x-filament-panels::form>
{{ $this->form }}
<x-filament-panels::form.actions
:actions="$this->getFormActions()"
/>
</x-filament-panels::form>
</x-filament-panels::page>
<x-filament-panels::page>
<x-filament-panels::form>
{{ $this->form }}
<x-filament-panels::form.actions
:actions="$this->getFormActions()"
/>
</x-filament-panels::form>
</x-filament-panels::page>
It isn't saving
Quin.
Quin.OP13mo ago
This is the form in the filament page
No description
Matthew
Matthew13mo ago
try this:
<x-filament-panels::page>
<x-filament-panels::form>
<form wire:submit="create">
{{ $this->form }}

<button type="submit">
Submit
</button>
</form>
<x-filament-actions::modals />
<x-filament-panels::form.actions
:actions="$this->getFormActions()"
/>
</x-filament-panels::form>
</x-filament-panels::page>
<x-filament-panels::page>
<x-filament-panels::form>
<form wire:submit="create">
{{ $this->form }}

<button type="submit">
Submit
</button>
</form>
<x-filament-actions::modals />
<x-filament-panels::form.actions
:actions="$this->getFormActions()"
/>
</x-filament-panels::form>
</x-filament-panels::page>
the problem is your are displaying the form, but not submitting it
Quin.
Quin.OP13mo ago
yeah now it is submitting but still not saving 🤔
Matthew
Matthew13mo ago
try now. I added a line
Quin.
Quin.OP13mo ago
When i submit him now i think he wants to add a modal beneath the button right?
No description
Matthew
Matthew13mo ago
If that doesnt work, try this trick to debug models: php artisan tinker RequestDomain::all()
Quin.
Quin.OP13mo ago
Just isn't creating them
No description
Samir
Samir13mo ago
Hi @Quin. Try based on my code. It is working for me. I have separate Seller panel with different Authentication guard. I am tring to fetch, edit or update my record in 'sellers' table whose resource is managed by Admin panel. Below is my working code for a Custom page created in Seller panel.
Quin.
Quin.OP13mo ago
I fixed it ty for all your answers guys 😄 i made a save function that we call on the action we give the wire:submit that function and it was done, made it all to complicated for my self
Want results from more Discord servers?
Add your server