Blade 用于显示的组件继承 collections。 Laravel 7
Blade components inheritance for displaying collections. Laravel 7
- Laravel版本:7.6.2
- PHP版本:7.3.7
- 数据库驱动&版本:10.3.16-MariaDB
描述:
我有几个匿名组件。组件 abstract
包含两个 blade yields
。在 excerpt
中,我想定义这些部分,但它似乎不起作用。
问题是每个 post 都有相同的 post-content
和 post-additions
。每个都有内容和 link 像第一个 post。 excerpt
中未覆盖的所有内容都以正确的方式显示。我在 Laravel 6 中使用了相同的方法,没有出现任何问题。
重现步骤:
遍历所有 posts 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
Post分量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
抽象post表示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>
我用一个简单的动作解决了这个问题:
在我的派生组件中,我将 @endsection
替换为 @overwrite
我遇到问题的地方。
- Laravel版本:7.6.2
- PHP版本:7.3.7
- 数据库驱动&版本:10.3.16-MariaDB
描述:
我有几个匿名组件。组件 abstract
包含两个 blade yields
。在 excerpt
中,我想定义这些部分,但它似乎不起作用。
问题是每个 post 都有相同的 post-content
和 post-additions
。每个都有内容和 link 像第一个 post。 excerpt
中未覆盖的所有内容都以正确的方式显示。我在 Laravel 6 中使用了相同的方法,没有出现任何问题。
重现步骤:
遍历所有 posts 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
Post分量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
抽象post表示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>
我用一个简单的动作解决了这个问题:
在我的派生组件中,我将 @endsection
替换为 @overwrite
我遇到问题的地方。