如何使用开关?

时间:2018-01-24 09:57:08

标签: blade laravel-5.5

我有blade布局用于生成消息。如何简化这个?

@if ($message = Session::get('success'))
    <div class="alert alert-success alert-block">
        <strong>{!! $message !!}</strong>
    </div>
@endif

@if ($message = Session::get('danger'))
    <div class="alert alert-danger alert-block">
        <strong>{!! $message !!}</strong>
    </div>
@endif

@if ($message = Session::get('warning'))
    <div class="alert alert-warning alert-block">
        <strong>{!! $message !!}</strong>
    </div>
@endif

@if ($message = Session::get('info'))
    <div class="alert alert-info alert-block">
        <strong>{!! $message !!}</strong>
    </div>
@endif

@if ($errors->any())
    <div class="alert alert-danger">
        Please check the form below for errors
    </div>
@endif

我想我必须创建一个数组['success', 'error', 'warning', 'info']并且ckeck如果它的任何值作为Session::get()的参数出现,而不是使用switch()将该值作为类名传递。

所以我想让它像

一样可用
@if ($message = Session::get($type))
    <div class="alert alert-<?=$type; ?> alert-block">
        <strong>{!! $message !!}</strong>
    </div>
@endif

1 个答案:

答案 0 :(得分:0)

试试这个:

@Injectable() 
export class LoginService {
    private logged:boolean;

    setlogged(data:boolean) {
        this.logged = data;
    }

    isLogged() {
        return this.logged;
    }