laravel check if laravel query is empty
if ($result->first()) { }
if (!$result->isEmpty()) { }
if ($result->count()) { }
if (count($result)) { }
laravel check if laravel query is empty
if ($result->first()) { }
if (!$result->isEmpty()) { }
if ($result->count()) { }
if (count($result)) { }
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)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us