wqa / nova-page-flexible-models

一个Laravel Nova扩展包,允许将模型作为灵活内容关联到页面

v1.4.0 2022-06-08 08:07 UTC

This package is auto-updated.

Last update: 2024-09-08 12:58:59 UTC


README

一个用于Laravel Nova的包,扩展了 Nova PageNova Flexible Content,允许您使用灵活内容将Laravel模型关联到您的Nova页面。

Testimonials example

安装

composer require wqa/nova-page-flexible-models

使用

在您的页面模板类中,必须包含 HasFlexibleModels 特性。

要添加一个灵活模型字段,请使用在字段定义中使用的 addFlexibleModelField 方法。

您可以使用 getFlexibleModels 方法从页面获取模型。这非常有用,如下所示使用辅助方法来保持您的blade文件整洁。

class AboutPage extends Template
{
    use WQA\NovaPageFlexibleModels\HasFlexibleModels;

    public function fields(Request $request)
    {
        return [
            Panel::make('Tesimonials', [
                $this->addFlexibleModelField('Testimonials', 'testimonials', Testimonial::class, 'author'),
            ])
        ];
    }

    public function testimonials(): Collection
    {
        return $this->getFlexibleModels('testimonials', Testimonial::class);
    }
}

要访问blade视图中的一些建议,您可以使用上述辅助方法,这将为您提供一个指定模型的集合。

@foreach (Page::testimonials() as $testimonial)
    <blockquote>
        {{ $testimonial->body }}
        <cite>{{ $testimonial->author }}</cite>
    </blockquote>
@endforeach