Laravel Classroom image

Anil  Bist / 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.

 
 
 
image
Anil  Bist

Skills    Laravel

Qualifications :- High School - SLV, College/University - Graphic Era Deemed Univ University,
Location :-Dehradun,Dehradun,Uttarakhand,India
Description:-

I started my Professional Journey in 2006 with one of the Web Development Company in Bangalore and my 1st framework was "Ruby on Rail" as Web development and delivered around 5+ Projects using this platform. Then came another dimension as JEE/Sturst framework, Gradually I realized that I want to build something on my own and give my passion and energy on creating something different a
Explore

 

  Students (0)