In this tutorial, I will show you how to write switch statements and multiple switch case in the Laravel blade file. You know that blade is a template engine and you can not define normal PHP without using the @php
@endphp
blade directive.
In Laravel blade, switch statements can be constructed using the @switch
, @case
, @break
, @default
and @endswitch
directives. Let's see the example code of a multiple switch case:
resources/views/welcome.blade.php
@switch($i)
@case(1)
First case...
@break
@case(2)
Second case...
@break
@default
Default case...
@endswitch
Hope it can help you.