Switch Case in Laravel
In this session, we will discuss how to use switch case in Laravel. In Laravel 5.5 and above versions @Switch is built into the Blade. So it can be used just like in plain PHP.
@switch($login_error)@case(1)
<span> `E-mail` input is empty! </span>
@break
@case(2)
<span>`Password` input is empty! </span>
@break
@default
<span>Something went wrong, please try again </span>
@endswitch
If you are using other versions of Laravel you can use plain PHP. You can use plain PHP in Blade. Another option is to use if else approach.
@if ($login_error == 1)`E-mail` input is empty!
@elseif ($login_error == 2)
`Password` input is empty!
@endif
Comments
0 comments
Please Sign in or Create an account to Post Comments