Hi guys. I not new in the Livewire ecosystem but I always have that question in my mind: What the best way to handle form inputs in Livewire?
Currently I'm building another livewire platform and I have that situation:
class EventPackage extends Component
{
public $slug;
public $paymentValue = 'full';
public $formSubmit = false;
// Form fields
public string $email = '';
public string $name = '';
public string $phone = '';
public string $user_id = '';
public string $address = '';
public string $complement = '';
public string $neighborhood = '';
public string $city = '';
public string $state = '';
public string $zip_code = '';
public string $church_name = '';
public string $gender = '';
public string $document_cpf = '';
public string $birthday = '';
public string $group_level_id = '';
public string $created_by_id = '1';
public bool $over_18 = false;
public function rules(): array
{
return [
'email' => 'required|email',
'name' => 'required|min:8',
'phone' => 'required|min:10',
'address' => 'required|min:3',
'complement' => 'nullable|min:3',
'neighborhood' => 'required|min:3',
'city' => 'required|min:3',
'state' => 'required|min:2',
'zip_code' => 'required|min:5',
'church_name' => 'required|min:3',
'gender' => 'required|numeric',
'document_cpf' => 'required|min:3',
'birthday' => 'required|date|min:3',
'over_18' => 'nullable|boolean',
'group_level_id' => 'required|numeric',
];
}
#[Computed]
public function eventPackage()
{
return \App\Models\EventPackage::with('items')
->where('slug', $this->slug)
->firstOrFail();
}
And now with Computed
and Locked
annotations I'm a bit confused when I need to use it.
In the case above, $slug
is the url parameter, and I need that to get the eventPackage
(I annotate with Computed
in this time).
But I dont know:
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community