Created
August 21, 2025 07:38
-
-
Save billydekid/ffc642bdc2780d00a67ff9fcb54f1938 to your computer and use it in GitHub Desktop.
Create public form with Livewire component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!-- resources/views/livewire/caritahu-form.blade.php --> | |
| <div class="mt-16"> | |
| <h2 class="text-2xl font-bold tracking-tight mb-4">Create Reservation</h2> | |
| <div class="bg-white p-6 rounded-md shadow-sm"> | |
| <form wire:submit="search"> | |
| {{ $this->form }} | |
| <button type="submit" class="bg-primary-600 text-white font-bold rounded-md px-3 py-2 tracking-tight mt-8"> | |
| Create | |
| </button> | |
| </form> | |
| </div> | |
| <x-filament-actions::modals /> | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* app/Livewire/CaritahuForm.php */ | |
| namespace App\Livewire; | |
| use Filament\Forms; | |
| use Filament\Forms\Get; | |
| use Livewire\Component; | |
| use Filament\Forms\Form; | |
| use Illuminate\Support\Facades\DB; | |
| use Filament\Forms\Components\Radio; | |
| use Illuminate\Contracts\View\View; | |
| use Filament\Forms\Contracts\HasForms; | |
| use Filament\Forms\Components\TextInput; | |
| use Filament\Forms\Components\DatePicker; | |
| use Filament\Forms\Concerns\InteractsWithForms; | |
| class CaritahuemisiForm extends Component implements HasForms | |
| { | |
| use InteractsWithForms; | |
| public ?array $data = []; | |
| public ?string $origin = null; | |
| public ?string $destination = null; | |
| public ?string $train_class = null; | |
| public function mount(): void | |
| { | |
| $this->form->fill(); | |
| } | |
| public function form(Form $form): Form | |
| { | |
| return $form | |
| ->schema([ | |
| Forms\Components\Fieldset::make('Reservasi') | |
| ->schema([ | |
| Forms\Components\Select::make('origin') | |
| ->label('Stasiun Asal') | |
| ->options(fn() => DB::table('stations')->pluck('station_name', 'id')) | |
| ->searchable(), | |
| // ->afterStateUpdated(fn() => $this->updated('origin')), | |
| Forms\Components\Select::make('destination') | |
| ->label('Stasiun Tujuan') | |
| ->options(fn() => DB::table('stations')->pluck('station_name', 'id')) | |
| ->searchable(), | |
| // ->afterStateUpdated(fn() => $this->updated('destination')), | |
| Forms\Components\Select::make('train_class') | |
| ->label('Kelas Kereta') | |
| ->options(fn() => DB::table('trainclasses')->pluck('class_name', 'class_code')) | |
| ->searchable(), | |
| // ->afterStateUpdated(fn() => $this->updated('train_class')), | |
| ]), | |
| ]) | |
| ->columns(1); | |
| // ->model(Reservation::class); | |
| } | |
| public function render(): View | |
| { | |
| return view('livewire.caritahuemisi-form'); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <x-app-layout> | |
| @livewire('caritahu-form') | |
| </x-app-layout> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment