Framework: Feature: Blade extension for check null and not null

Created on 6 Sep 2016  路  7Comments  路  Source: laravel/framework

I think would be nice if blade has an extension to perform a check for null and not null.

The extension maybe like this:

@ifNull ($comments)
@ifNotNull ($comments)

I know we can perform it just by using like @if (! is_null($comments)), but as I said before, I think would be nice if blade has its feature. Thankyou

Most helpful comment

@if($foo === null) is already fine.

All 7 comments

How about create a separate package? a collection of blade extensions. using is_null() and ! is_null() seems to be much more okay for me.

@if($foo === null) is already fine.

@daison12006013 hmm, what do you mean about a separate package? Do you mean like this ?
Yes, I can make its extension by myself, but I just think that would be nice if it has been available by default.

@GrahamCampbell Maybe yes, maybe no. It's okay, it's only my opinion.

@nmfzone, it is not a good design, imagine you are linking an statement along condition, in which you should need to apply not just the null but all the predefined conditions such as in_array() empty() and so on, they are so many.

@daison12006013 Aaah, i think there is a misconception in here. The purpose of this extension is only for a condition that only need to perform null check or not null check. So, I give an example that it only performs null or not null check. If there is not only perform null or not null check, we can back to @if.
Another topic, in_array() and empty() also could be another extension if we need it. @ifInArray and @ifEmpty.
I just thinking about the reason behind is_null(). We could use like what had been mentioned by @GrahamCampbell, but PHP still gives is_null().

That's my point @nmfzone, having those condition types would probably take a lot of extensions and yet those native functions is much more better.

How about @empty() with @else to check if the string/array/null is empty.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jackmu95 picture jackmu95  路  3Comments

Fuzzyma picture Fuzzyma  路  3Comments

PhiloNL picture PhiloNL  路  3Comments

iivanov2 picture iivanov2  路  3Comments

SachinAgarwal1337 picture SachinAgarwal1337  路  3Comments