mercredi 3 mai 2017

How to check if a variable has data in laravel blade

I wanted to check if variable is there or not in blade ..for that i have used following lines:

@if(is_null($products))
    <div class="alert alert-warning">
        <strong>Sorry!</strong> No Product Found.
    </div>                                      
@else

    @foreach($products as $product)
        //
    @endforeach
@endif

The problem is when there is $products on blade i could show inside of foreach loop but when i get empty variable.i couldn't show the message "No Data Found" instead it shows only empty space? is there any problem of checking variable inside of blade?

Controller code :

public function productSearch(Request $request)
    {
        $name = $request->name; 
        $products = Product::where('name' , 'like', '%'.$name.'%')->get();
        return view('cart.product',compact('products'));
    }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire