所有的blade模板解析后的文件存在\storage\framework\views目录下
1、读取配置
// 读取config/blog.php中的title属性值
{
{ config('blog.title') }}
2、分页
调用分页paginate方法返回如下数据
// 可以调用任何分页相关属性
LengthAwarePaginator {
#160 ▼
#total: 17
#lastPage: 2
#items: Collection {#171 ▶}
#perPage: 10
#currentPage: 1
#path: "http://myblog.com/blog"
#query: []
#fragment: null
#pageName: "page"
}
// 这里是以函数的方式调用
// 当前页
{
{ $posts->currentPage() }}
// 最后一页
{
{ $posts->lastPage() }}
// 前一页
<a href="{!! $posts->previousPageUrl() !!}">
<a href="{!! $posts->url($posts->currentPage() - 1) !!}">
// 后一页
<a href="{!! $posts->nextPageUrl() !!}">
// 当出现错误时,old方法会读取之前输入的值
<input type="text" class="form-control" id="name" name="name" value="{
{ old('name') }}">
3、使用自定义函数
// 这里的str_limit调用的是vendor\laravel\framework\src\Illuminate\Support\helpers.php里的方法
// 如果content属性不存在的话(也可以指别名),可以通过在Post模型里设置 getContentAttribute(get属性Attribute) 方法返回一个存在的字段
public function getContentAttribute($value)
{
return $this->content_raw;
}
// 默认100个字符,超过后跟...
{
{ str_limit($post->content) }}
// url链接
<form class="form-horizontal" role="form" method="POST"
action="{
{ url('/auth/login') }}">
4、循环
// 格式 @foreach ($posts as $post)xxxxxxx@endforeach
@foreach ($posts as $post)
<li>
<a href="/blog/{
{ $post->slug }}">{
{ $