【问题标题】:Blade components inheritance for displaying collections. Laravel 7用于显示集合的刀片组件继承。拉拉维尔 7
【发布时间】:2020-08-03 01:52:01
【问题描述】:

  • Laravel 版本:7.6.2
  • PHP 版本:7.3.7
  • 数据库驱动程序和版本:10.3.16-MariaDB

    说明:

我有几个匿名组件。组件abstract 包含两个刀片yields。在excerpt 我想定义这些部分,但它似乎不起作用。 问题是每个帖子都有相同的post-contentpost-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


【解决方案1】:

我通过一个简单的动作解决了这个问题:
在我的派生组件中,我将 @endsection 替换为 @overwrite 我遇到了问题。

【讨论】:

  • 这真的帮助了我,谢谢。我被困了很久。
猜你喜欢
  • 1970-01-01
  • 2021-07-05
  • 1970-01-01
  • 2021-05-04
  • 1970-01-01
  • 2019-04-24
  • 2018-02-13
  • 2019-05-26
  • 2018-11-12
相关资源
最近更新 更多