Reputation: 1347
There is a model event. I wanna update it. The custom request is used for validation, but have several problems. Every event has two user's relations - client and executor. As an example, I wanna change the event time. That time should be after now and should be free in the executor. The first validation rule is simple, but for the second I have to initialize the event model in custom request, retrieve the executor and his free time. Of course, I can do something like that
$event = Event::find($id);
$executor = $event->executor;
But is it good way to process validation? Do not think so. What the better way to validate that data?
Upvotes: 0
Views: 132
Reputation: 5030
as its not a simple rule you can use laravel sometimes:
$validator->sometimes('event', 'required|max:500', function ($input) {
$event = Event::find($id);
$executor = $event->executor;
return $executer->isFree(time);
});
Upvotes: 1