【发布时间】:2020-08-03 01:52:01
【问题描述】:
- Laravel 版本:7.6.2
- PHP 版本:7.3.7
- 数据库驱动程序和版本:10.3.16-MariaDB
说明:
我有几个匿名组件。组件abstract 包含两个刀片yields。在excerpt 我想定义这些部分,但它似乎不起作用。
问题是每个帖子都有相同的post-content 和post-additions。每个都有内容和链接,就像第一篇文章一样。 excerpt 中未覆盖的所有内容都以正确的方式显示。我在 Laravel 6 中使用了相同的方法,没有任何问题。
复制步骤:
遍历所有帖子views\components\posts\catalogue.blade.php:
@forelse($posts as $post)
<x-posts.representations.excerpt :post="$post"
:class="($loop->last) ? 'post_box_last' : ''" />
@empty
<h3>Unfortunately, there are no posts for you..</h3>
@endforelse
发布组件views\components\posts\representations\excerpt.blade.php:
@extends('components.posts.representations.abstract')
@props(['post'])
@section('post-content')
<p>{{ $post->excerpt }}</p>
@endsection
@section('post-additions')
<a href="{{ route('main.posts.show', ['post' => $post->uri_alias]) }}" class="more float_r">Continue Reading</a>
@endsection
抽象帖子表示views\components\posts\representations\abstract.blade.php:
<div {{ $attributes->merge(['class' => 'post_box']) }}>
...
<div class="post_box_right">
<h2>{{ $post->name }}</h2>
...
@yield('post-content')
@yield('post-additions')
</div>
</div>
【问题讨论】:
-
你弄明白了吗?我有同样的问题:-(
-
是的,我在谷歌上下搜索,终于找到了解决方案。答案在这里。
-
太好了,谢谢!有趣的是,我在 Laravel github 上问了这个问题,主角 Taylor 自己回答了,但给了我一个完全不同的答案 :-)
-
泰勒给出了什么答案?
标签: php laravel components laravel-blade laravel-7