I'm building an app using Livewire. If you have some experience with Livewire please take some time to answer.
I'm trying to keep my livewire components code clean. How we can separate validation logic just like custom Requests in the controller as there is not Request object in the Livewire component.
My current approach: I make separate method for validation for now? But I'm looking for something much better like custom Requests.
class Add extends Component
{
public function store()
{
$this->Validation();
$property = new Property();
$property->user_id = ...
}
}
Also, If is there any better approach for structuring components? My current approach is below:
Any suggestions will be appreciated.
Top comments (2)
A little late to respond but one accepted way to extract validation logic is to add it to the model. It looks like this:
Then in Livewire you can do:
That's pretty nice. But it will be more pretty strecture like CustomFormRequest. Anyway Thank You so much