Switch in Laravel 5 - Blade

后端 未结 8 521
南旧
南旧 2021-02-02 05:10

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         


        
8条回答
  •  梦谈多话
    2021-02-02 05:24

    To overcome the space in 'switch ()', you can use code :

    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)/', '

提交回复
热议问题