2

I have two return varibles from controller to view in Laravel.

return view ('home', compact('books','count'));

Now I want to display one section('content') @if the conditon is true in my home.blade.php. How I can do this. Now section('content') will display @if condition is false

@if (!empty($books))
 @section('content')
@endif
FULL STACK DEV
  • 15,207
  • 5
  • 46
  • 66
Anu Alex
  • 230
  • 2
  • 5
  • 19

1 Answers1

2

You can use @else, @elseif, @unless

Here is an example

@if (count($books))
 section('content')
@else
 @section('your other section')
@endif

Hope this helps

FULL STACK DEV
  • 15,207
  • 5
  • 46
  • 66
  • if condion is always satisfy, i check $books value when if condion is false. It returns [] . What is this result means. Am I check @if($books !== null) instead of @if (!empty($books)) – Anu Alex Mar 05 '18 at 07:12
  • @anu you show `no records found` if condition is false – FULL STACK DEV Mar 05 '18 at 07:13
  • Yea but always true condition is satisfied even if $books has nothing. And I checked $books value when if condion is false. But $books echoing [] . – Anu Alex Mar 05 '18 at 07:15
  • @anu you can use `count()` – FULL STACK DEV Mar 05 '18 at 07:19
  • Fantastic. It works. Greatful to you Sir.It really killed my 4 days. From where you get this count function. It is not in laravel documentation – Anu Alex Mar 05 '18 at 07:25