Laravel Classroom image

Yasar  Khan / Professional / Web Technology

 
To post your Question Join Classroom
 
Lesson Topics's No:-  First|1 | 2 | 3|Last
Lessons:-Blade Templates

13.2 Logic
What about foreach() loops? I use loads of them! I use a lot of if and else too. Blade simplifies
all of these conditional statements through the use of the magical @ sign, let’s take a look.1 <?php
2
3 @foreach ($users as $user)
4 <div class="user">{{ $user->name }}</div>
5 @endforeach
There, not only cleaner looking than all of those ugly PHP tags, but a lot quicker to write! What
about ifs and elseifs? Well if you are used to PHP alternate syntax you will be able to guess
the result. Simply replace the <?php with @ and skip the ‘ : ?>‘ all together! What we have left
is..
1 @if ($user->name == 'Dave')
2 <p>Welcome Dave!</p>
3 @else
4 <p>Welcome Guest!</p>
5 @endif
Very simple! Here are the other operators you can use with Blade, they should look familiar :
1 <?php
2
3 @for ($i =0; $i < 100 - 1; $i++)
4 Number {{ $i }}<br />
5 @endfor
a standard for loop and..
1 <?php
2
3 @forelse ($users as $user)
4 {{ $user->name }}
5 @empty
6 <p>There are no users.</p>
7 @endforelse
That last one is a little special. The forelse() statement acts as a foreach() loop, but with an
extra @empty which will output the result below if the supplied array is empty (has no length).
This is very handy since it avoids the need for adding an extra if statement.

 
 
 

Yasar  Khan

Skills    Laravel

Qualifications :-
Location :-Dehradun,Dehradun,Uttarakhand,India
Description:- Hi i am yasar working as web developer since last 3 years.
Explore
 

  Students (0)