Courses

Advanced Laravel Livewire

Reset Values To Original State: Mount or Not Mount?

Previous: Click.prefetch: Make External Data Load "Instantly"
avatar

Povilas how do you reset properties that are model binded (e.g. public Post $post)? say i want to reset a post title so i do this: $this->reset('post.title') but it doesnt work.

avatar

To be honest, I haven't tried that way. Would $post->title = '' work maybe?

avatar

i did it using this way: $this->post->title = ''

wanted to use the $this->reset way but i guess its not possible. thanks Povilas!

avatar

$this->reset way may not properly work in this case.. $this->post->title = '' will update previous created record. you can reassign new post model instance to post property after saving new record...

$this->post = new Post();

avatar
You can use Markdown
avatar
You can use Markdown