Support the ongoing development of Laravel.io →
Alpine.js Laravel Blade

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:

  • what need to be computed?
  • what need to be locked?
  • I need to declare every form input as a variable in the component? I have another option?
  • Is this safe?
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.