My aim is to adapt the following controller methods to follow the DRY principle by moving the validation to form requests. However, I have a problem which is that there are overlaps between validation for different methods. For example, let's say that the input form has only one field and that's name
, and that it's related to a Task
model. Let's consider 3 controller methods now:
store
method: validate thatname
isn't emptyupdate
method: validate thatname
isn't empty and that aTask
with the given$id
existsdestroy
method: validate that aTask
with the given$id
exists
So for the store
method I am checking the first assumption, for the destroy
method I am checking the second assumption, and for the update
method I am checking both.
So, ideally, I would like to be able to do something like...
public function store(StoreTask $request)...
public function update(Store Task TaskExists $request, $id)...
public function destroy(TaskExists $id)...
...but I am very unclear on how to write the syntax for this, and whether there is some other approach which I'm missing to accomplish the same thing.
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/34Buj64
via IFTTT
Aucun commentaire:
Enregistrer un commentaire