//定义布局
<html>
<head>
<title>App Name - @yield('title')</title>
</head>
<body>
@section('sidebar')
This is the master sidebar.
@show //@show 则在定义的同时 立即 yield 这个片段
<div class="container">
@yield('content')
</div>
</body>
</html>
//扩展布局
@extends('layouts.app')
@section('title', 'Page Title')
@section('sidebar')
@parent //@parent 指令向布局的 sidebar 追加(而非覆盖)内容
<p>This is appended to the master sidebar.</p>
@endsection //@endsection 指令仅定义了一个片段
@section('content')
<p>This is my body content.</p>
@endsection
//将被 PHP 的 htmlspecialchars 函数自动转义以防范 XSS 攻击
{{ $name }}
//展示非转义数据
{!! $name !!}
//json数据
<script>
var app = @json($array);
</script>
//php
@php
//
@endphp
// If 语句
@if (count($records) === 1)
// 有一条记录
@elseif (count($records) > 1)
// 有多条记录
@else
// 没有记录
@endif
//循环
@for ($i = 0; $i < 10; $i++)
The current value is {{ $i }}
@endfor
@foreach ($users as $user)
<p>This is user {{ $user->id }}</p>
@endforeach
@forelse ($users as $user)
<li>{{ $user->name }}</li>
@empty
<p>No users</p>
@endforelse
@while (true)
<p>I'm looping forever.</p>
@endwhile
@foreach ($users as $user)
@if ($user->type == 1)
@continue
@endif
<li>{{ $user->name }}</li>
@if ($user->number == 5)
@break
@endif
@endforeach
@foreach ($users as $user)
@if ($loop->first)
This is the first iteration.
@endif
@if ($loop->last)
This is the last iteration.
@endif
<p>This is user {{ $user->id }}</p>
@endforeach