Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

null check nested object laravel

object_get($model, 'nested.relation.field')

Example:
$model = Book::with('author.country')->findOrFail($id);
$country_name = array_get($model->toArray(), 'author.country.name');
// or
$country_name = object_get($model, 'author.country.name');
 
PREVIOUS NEXT
Tagged: #null #check #nested #object #laravel
ADD COMMENT
Topic
Name
6+5 =