mafortis
mafortis

Reputation: 7128

Laravel is and is not empty value check

I know we can check whether value is empty or not like:

@if(!empty(test))
//print results
@endif

but what if we want to cross check 2 columns for being empty and not being empty?

Sample:

I want check between: $test->one and $test->two

  1. If $test->one is not empty and $test->two is empty = x
  2. If $test->one and $test->two both are not empty = y

How do I do that?

UPDATE

My code:

PS:

  1. $test->one in my sample is equal to $order->options_price

  2. $test->two in my sample is equal to $order->shipment_price

    @if(!empty($order->product_data))

      {{ number_format($order->total_price(), 0) }}
    
    @elseif(!empty($order->options_price) && empty($order->shipment_price))
    
      {{ number_format($order->quantity * $order->price + $order->options_price, 0) }}
    
    @elseif(!empty($order->options_price) && !empty($order->shipment_price))
    
      {{ number_format($order->quantity * $order->price + $order->options_price + $order->shipment, 0) }}
    
    @else
    
      {{ number_format($order->quantity * $order->price, 0) }}
    
    @endif
    

The problem is i cannot get shipment_price

FIXED:

I did have typing mistake in my code.

Upvotes: 0

Views: 634

Answers (2)

user320487
user320487

Reputation:

Laravel also provides the blank helper method.

Examples from the docs:

blank('');
blank('   ');
blank(null);
blank(collect());

// true

blank(0);
blank(true);
blank(false);

// false

Upvotes: 0

Prince Lionel N'zi
Prince Lionel N'zi

Reputation: 2588

You can do

If $test->one is not empty and $test->two is empty

@if(!empty($test->one) && empty($test->two))
//print results
@endif

If $test->one and $test->two both are not empty

@if(!empty($test->one) && !empty($test->two))
//print results
@endif

Upvotes: 2

Related Questions