Tangible Bytes

A Web Developer’s Blog

Laravel Object Validation Closure

I’m using Laravel Inertia and the resulting form submission returns JSON objects - which I wanted to validate.

In my case I have a quiz - which has questions which in turn have answers and those answers have user-submitted responses.

If the CMS editor tries to delete answers which have responses this will result in an SQL referential integrity error - so I want a validation rule for each answer which says

If the answer object has property “deleted” and the database has responses for this answer - fail.

Read more ...