<?php
namespace App\Livewire;
use App\Models\ContactMessages;
use Filament\Forms;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
use Livewire\Component;
use Illuminate\Contracts\View\View;
class CreateCm extends Component implements HasForms
{
use InteractsWithForms;
public ?array $data = [];
public function mount(): void
{
$this->form->fill();
}
public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('first_name')
->required()
->maxLength(100),
Forms\Components\TextInput::make('last_name')
->required()
->maxLength(100),
Forms\Components\TextInput::make('email')
->email()
->required()
->maxLength(255),
Forms\Components\TextInput::make('phone_number')
->tel()
->maxLength(20)
->default(null),
Forms\Components\Textarea::make('message')
->required()
->columnSpanFull(),
Forms\Components\TextInput::make('ip_address')
->maxLength(45)
->default(null),
])
->statePath('data')
->model(ContactMessages::class);
}
public function create(): void
{
$data = $this->form->getState();
$record = ContactMessages::create($data);
$this->form->model($record)->saveRelationships();
}
public function render(): View
{
return view('livewire.create-cm');
}
}