Skip to content
Advertisement

Check if hasMany Relationship Exists in Laravel 8 Before Deleting Record

I am trying to check if a relationship exists prior to deleting it. I’ve seen many other posts online about this, but can’t seem to make it work–when I hit delete it ignores my @if statement and deletes the record.

Models/Workorder.php

JavaScript

Models/Continuation.php

JavaScript

workorders/index.blade.php

JavaScript

Workorders/Index.php

JavaScript

Advertisement

Answer

Try something like that by using isNotEmpty()

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement