can i create a form in app/Filament/Pages/CreateModelname.php?

A form which i use only to create a record? i tried:
<?php

namespace App\Filament\Resources\AvailabilityResource\Pages;

use App\Filament\Resources\AvailabilityResource;
use Filament\Resources\Pages\CreateRecord;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\DateTimePicker;
use App\Models\ReservableItem;

class CreateAvailability extends CreateRecord
{
public static $resource = AvailabilityResource::class;

public function form()
{
return parent::form()->schema([
Select::make('reservable_item_id')
->label('Reservable Item')
->options(
ReservableItem::all()->pluck('id', 'name')->toArray()
)
->placeholder('Select an Item'),
DateTimePicker::make('start_time')
->label('Start Time')
->withTimezone()
->required(),
// add other fields as necessary
]);
}
}
<?php

namespace App\Filament\Resources\AvailabilityResource\Pages;

use App\Filament\Resources\AvailabilityResource;
use Filament\Resources\Pages\CreateRecord;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\DateTimePicker;
use App\Models\ReservableItem;

class CreateAvailability extends CreateRecord
{
public static $resource = AvailabilityResource::class;

public function form()
{
return parent::form()->schema([
Select::make('reservable_item_id')
->label('Reservable Item')
->options(
ReservableItem::all()->pluck('id', 'name')->toArray()
)
->placeholder('Select an Item'),
DateTimePicker::make('start_time')
->label('Start Time')
->withTimezone()
->required(),
// add other fields as necessary
]);
}
}
but does not work.
2 Replies
ByteXR
ByteXRβ€’2y ago
Isn't there a method getFormSchema?
Falk Maria Zeitsprung
Falk Maria ZeitsprungOPβ€’2y ago
Thanks @bytexr ! Great πŸ™‚
Want results from more Discord servers?
Add your server