To create a new page, you can use:
php artisan make:filament-page TestNow, we need to implement an interface and add a trait to use Filament forms.
app/Filament/Pages/Test.php:
<?php
namespace App\Filament\Pages;
use Filament\Forms\Form;
use Filament\Pages\Page;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Placeholder;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Pages\Concerns\InteractsWithFormActions;
class Test extends Page implements HasForms
{
use InteractsWithForms, InteractsWithFormActions;
public ?array $data = [];
protected static ?string $navigationIcon = 'heroicon-o-document-text';
protected static string $view = 'filament.pages.test';
public function mount(): void
{
$this->form->fill();
}
public function form(Form $form): Form
{
return $form
->schema([
TextInput::make('no1')->required()
->integer()
->live(),
TextInput::make('no2')->required()
->integer()
->live(),
Placeholder::make('created1')
->label('Output'),
Placeholder::make('created2')
->hiddenLabel()
->content(function($record, $get) {
return ($get('no1') + $get('no2'));
} )
// ...
])
->statePath('data');
}
}
And we need to render the form in the Blade file.
resources/views/filament/pages/test.blade.php:
<x-filament-panels::page>
<x-filament-panels::form>
{{ $this->form }}
</x-filament-panels::form>
</x-filament-panels::page>
for detail refer https://laraveldaily.com/post/filament-edit-only-single-record-custom-page
Leave a Reply