Laravel Tutorial Day 3

Learning Objectives: Till now you have learned the basics of Laravel to create pages and set URLs for the website. Now it’s time to learn the core element structures like loops, conditions, and so on.

PHP Laravel if else if endif Examples:

@if (count($records) === 1)
I have one record!
@elseif (count($records) > 1)
I have multiple records!
@else
I don't have any records!
@endif

PHP Laravel switch Examples:

@switch($i)
    @case(1)
        First case…
       @break
    @case(2)
        Second case…
        @break
    @default
       Default case…
@endswitch

PHP Laravel for loop Examples:

@for ($i = 0; $i < 10; $i++)
{{ $i }}
@endfor

PHP Laravel foreach loop Examples:

@foreach ($items as $item)
{{ $item->name }}
@endforeach

PHP Laravel while loop Examples:

@while ($i < 10)
{{ $i }}
$i++
@endwhile

How to add PHP code directly into Larave? Here are the examples:

@php
    $counter = 1;
@endphp

How to protect form using CSRF (Need this in each form for the security purpose)

<form method="POST" action="/profile">
    @csrf
 
    ...
</form>

how to add methods into the form?

Since HTML forms can’t make PUTPATCH, or DELETE requests, you will need to add a hidden _method field to spoof these HTTP verbs. The @method Blade directive can create this field for you: Reference

<form action="/foo/bar" method="POST">
    @method('PUT')
 
    ...
</form>

For more fundamental syntax have a look @ Official Laravel Docs