code-8
code-8

Reputation: 58652

Isset check on Array - Blade Laravel 5.8

If I do

{{ dd($alert) }}

I got

array:7 [▼
  "created_at" => "2019-12-30 17:31:55.728307+00:00"
  "fail_cnt" => 123
  "updated_at" => "2019-12-30 17:31:55.728307+00:00"
]

Hints: It is an array, not an object.

I'm trying to use the isset check on an array

<input required type="number" name="slaac" class="form-control form-control-sm"  placeholder="1000" value="{{ $alert['slaac_threshold'] or '' }}">

I kept getting

What did I do wrong ?

Upvotes: 0

Views: 515

Answers (1)

lagbox
lagbox

Reputation: 50491

Just use the null coalescing operator ?? instead:

{{ $alert['slaac_threshold'] ?? '' }}

The OR operator in Blade was removed in Laravel 5.7 and never quite worked correctly.

"The Blade "or" operator has been removed in favor of PHP's built-in ?? "null coalesce" operator, which has the same purpose and functionality" - Laravel 5.7 Docs - Upgrade Guide - Blade

PHP.net Manual - 7.0 New Features - Null Coalesce

Upvotes: 3

Related Questions