Answers for "laravel check if relation is null"

PHP
0

laravel check if relation is null

// filter models that do not have any related items:
1. Model::has('relation')->get()

// Once you have a model, if you already have loaded the collection, 
//  you can check the count of the collection:
2. $model->relation->count();

// If you want to check without loading the relation, 
// you can run a query on the relation:
3. $model->relation()->exists();

4. count($model->relation)
  
5. is_null($model->relation)
Posted by: Guest on June-29-2021

Browse Popular Code Answers by Language