Laravel check if relation is empty
There are a variety of ways to do this. #1 In the query itself, you can filter models that do not have any related items: Model::has(‘posts’)->get() #2 Once you have a model, if you already have loaded the collection (which below #4 checks), you can call the count() method of the collection: $model->posts->count(); #3 If … Read more