Accessing request() or unbind data

I’m in a situation where I created a Livewire form and I do want some properties to be bound to the Livewire two-way-binding system, so I placed them as public properties and they work ok.

This form also has a bunch more fields I’d like to use and update on the form submit but I do NOT want them to be “synchronised” or binded.

So I just thought about doing this:

<!-- myform.blade.php -->
<form wire:submit.prevent="updateForm">
    <input type="text" wire:model="name2way" />
    <input type="text" name="name1way" />
    <button>Submit</button>
</form>
//Myform.php
public $name2way;

function updateForm(){
    dd(request('name1way'), $this->name2way);
}

In this case when “dding” both fields, the request('name1way') is empty and $this->name2way is filled.

same is true for Request $request (of course)

function updateForm(Request $request){
    dd($request->name1way);
}

I don’t want a request back-and-forth for every single field I don’t need to be 2-way bound, and I don’t want to create single components for every field that does need this feature.

Is there a way to access request() within Livewire?

<form wire:submit.prevent="submit(Object.fromEntries(new FormData($event.target)))">

public function submit($formData)
{
    //$formData should be an array
}
1 Like