Open Laboratory for Technocrats

Grab the developer role, learn concepts & prepare with senior software engineers to get solutions for problems in a software job. Coding and Programming Solutions crafted for you.

Laravel 5.8 - Blade - OR Operator - Solution

Laravel 5.8 - Blade - OR Operator
Laravel 5.8 - Blade - OR Operator 
OR operator in the PHP Laravel 5.7 blade template engine is deprecated.

On using this we get the undefined variable error on the development machine.

What OR operator used to do in BLADE?
OR operator used to save a few extra words of code on the developer machine.
Example
{{$testVariable or 'TestValue' }}
This will compile to
isset( $testVariable ) ?  $testVariable : 'TestValue';

What's the solution then?

Laravel 5.8 - Blade - OR Operator
Laravel 5.8 - Blade - OR Operator 

Now since Laravel 5.7, this OR operator has been deprecated we can get the same result with PHP's built-in ?? "null coalesce" operator

Example for the same as goes
{{$testVariable ??  'TestValue' }}
So now we can use this null coalesce operator to get the desired result which OR operator was giving in the Blade templating engine.

 Keep Coding and Keep Smiling :)

Top #3 Articles

Most Read