How can I use switch in blade templates? When I used:
@switch($login_error)
@case(1)
`E-mail` input is empty!
@break
@case(2)
`Pa
You can just add these code in AppServiceProvider class boot method.
Blade::extend(function($value, $compiler){
$value = preg_replace('/(\s*)@switch\((.*)\)(?=\s)/', '$1', $value);
$value = preg_replace('/(\s*)@case\((.*)\)(?=\s)/', '$1case $2: ?>', $value);
$value = preg_replace('/(?<=\s)@default(?=\s)/', 'default: ?>', $value);
$value = preg_replace('/(?<=\s)@breakswitch(?=\s)/', '
then you can use as:
@switch( $item )
@case( condition_1 )
// do something
@breakswitch
@case( condition_2 )
// do something else
@breakswitch
@default
// do default behaviour
@breakswitch
@endswitch
Enjoy It~