Hi
As i'm trying to make some projects to learn Livewire (without jetstream), i'm encountering some behaviours that i'm not sure of if i've implemented them correctly.
In a basic crud setup i still have a normal resource controller to make my routes with, from which i have excluded the ones that livewire will use like store, edit, etc.
So when i want to show a page for a crud item itself via my resource controller's show method, i'm not sure how to pass data to the livewire component.
Inside my resource controller the show method just does the following:
public function show(Post $post)
{
return view('post.index', compact(['post']));
}
Then in my post index.blade.php file i do the following:
<div>
@livewire('show-post', ['post' => $post])
</div>
Inside my component i do the following to populate the input fields via the mount method:
class ShowPosts extends Component
{
public $post;
public $subject, $message, $user_id;
public function mount(Post $post)
{
$this->subject = $post->subject;
$this->message = $post->message;
$this->user_id = Auth::id();
}
public function render()
{
return view('livewire.show-posts');
}
}
I found that i have to populate the properties inside the mount method so that when i edit the post the properties also update upon saving, otherwise when i populate them inside the render method i have to refresh the entire page.
My question would be that if this is the correct way to pass certain data to a livewire component when it's not used as a full page component through a route?
The reason i also ask this is that when i set validation rules and try to update the post, if i let the validation fail on the $message property and let the validation pass on the $subject property, the $subject property will reflect the change if you print it out, untill the page refreshes then it reverts back to what is stored but not changed in the database record.