Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
366 views
in Technique[技术] by (71.8m points)

laravel - Updating input field by leaving

Is it possible with Laravel livewire to change a field in the database when leaving the input field?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use wire:model.lazy to achieve an action when leaving (loosing focus) on an input field.

<div>
    <input type="text" class="form-control" wire:model.lazy="billingRate">
</div>

class Rate extends Component
{
     public $billingRate;


    public function updatedBillingRate(){

       dd($this->billingRate);     // don't forget to use $this to access class property

        // persist to database here
    }
}

In the above example, whenever billingRate value changes, it will trigger the updatedBillingRate() method.

Please checkout a similar thred on laracast here (https://laracasts.com/discuss/channels/livewire/livewire-how-to-action-the-value-of-an-input-without-a-button)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...