laravel项目实践:模板

Blade 是由 Laravel 提供的非常简单但功能强大的模板引擎

继承: 

@section('sidebar')

@yield('content')

@section('content')

    <p>这里是主体内容,完善中...</p>

@endsection


组件与插槽的数据传递: 

 <div class="alert alert-danger">

    <div class="alert-title">{{ $title }}</div>

    {{ $slot }}

</div>


@component('alert')

    @slot('title')

        Forbidden

    @endslot


    You are not allowed to access this resource!

@endcomponent


数据显示:

Route::get('greeting', function () {

    return view('welcome', ['name' => '学院君']);

});

你好, {{ $name }}。

{{ isset($name) ? $name : 'Default' }} 

{{ $name or 'Default' }}


流程控制:

@if (count($records) === 1)

    I have one record!

@elseif (count($records) > 1)

    I have multiple records!

@else

    I don't have any records!

@endif


认证指令

@auth

    // 用户已登录...

@endauth


@guest

    // 用户未登录...

@endguest