Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Blade how to use if statement for null or empty

Tags:

php

laravel

blade

In the Blade templating engine, how to use "if" to determine null or empty?

{{{ Auth::user()->age }}}

like image 468
paradox Avatar asked May 14 '15 18:05

paradox


People also ask

IS NULL in if condition Laravel?

How check variable is NULL or not in laravel? The is_null() function checks whether a variable is NULL or not. This function returns true (1) if the variable is NULL, otherwise it returns false/nothing.

How do I check if a column is empty in Laravel?

You can check if the column value of a record is null or not in laravel using whereNotNull() and exists() method. exists() method returns false if the column value of a record in the table is null and it returns true if column value is not null.

What is __ In Laravel blade?

The __ helper function can be used to retrieve lines of text from language files. You can retrieve lines of text from either key-based translation files (represented as PHP arrays) or from literal, string-based translation files (represented as a JSON object). Replacements are passed as a key/value pair.


1 Answers

You can do it as bellow

    @if (empty(Auth::user()->age))
      // your if code
    @else
     //  your else code
    @endif
like image 97
Vishal Wadhawan Avatar answered Oct 21 '22 04:10

Vishal Wadhawan