PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, January 26, 2022

[FIXED] Isset check on Array - Blade Laravel 5.8

 January 26, 2022     laravel, laravel-5, laravel-5.8, laravel-blade, php     No comments   

Issue

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 ?


Solution

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



Answered By - lagbox
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing