I have this kind of test again, and again, and I feel like there is a more elegant way to do it.
(isset($country['capital'])) ? $country['capital'] : null Can you help me?
You can use or Operator In Laravel Blade template
$country['capital'] or null And In php 7 you can use Null coalescing operator
$country['capital'] ?? null The null coalescing operator (??) has been added as syntactic sugar for the common case of needing to use a ternary in conjunction with isset(). It returns its first operand if it exists and is not NULL; otherwise it returns its second operand.
or won't do much. It's not Laravel, it's PHP (unless I'm really missing something about Laravel overloading PHP operators!?).or works for laravel not in <?php ... ?> tag, at my end.Since PHP 7 you can do
$country['capital'] ?? null;
isset()are useless. Put the whole ternary operator between parentheses while nesting them or in string concatenation. But the null coalescing operator is the way to go if you have PHP7