ventaquil ventaquil - 1 month ago 32
PHP Question

Switch in Laravel 5 - Blade

How can I use switch in blade templates? When I used:

@switch($login_error)
@case(1)
`E-mail` input is empty!
@break
@case(2)
`Password` input is empty!
@break
@endswitch


in result I see this text as plaintext. I prefer to use switch in few piece of code because it's more clean for me than when I using if.

But if it's not possible just write it.

Answer

Unfortunately Laravel Blade does not have switch statement. You can use Laravel if else approach or use use plain PHP switch. You can use plain PHP in blade templates like in any other PHP application.