在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):whitecube/nova-flexible-content开源软件地址(OpenSource Url):https://github.com/whitecube/nova-flexible-content开源编程语言(OpenSource Language):PHP 72.8%开源软件介绍(OpenSource Introduction):An easy & complete Flexible Field for Laravel Nova, perfect for repeated and flexible field groups. Quick startHere's a very condensed guide to get you started asap. See the full docs at https://whitecube.github.io/nova-flexible-content Install
UsageA flexible field allows easy management of repeatable and orderable groups of fields. As opposed to the few existing solutions for Laravel Nova, this one does not have constraints on which fields you are allowed to use within these groups. That means you can use all Laravel Nova field types, and also any community-made fields. Adding layoutsA layout represents a group of fields that can be repeated inside the Flexible field. You can add as many layouts as you wish. If only one layout is defined the field will behave like a simple Repeater and by adding more layouts you'll obtain a Flexible Content. Both concepts are similar to their cousins in Wordpress' ACF Plugin. Layouts can be added using the following method on your Flexible fields: addLayout(string $title, string $name, array $fields) The use Whitecube\NovaFlexibleContent\Flexible;
/**
* Get the fields displayed by the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function fields(Request $request)
{
return [
// ...
Flexible::make('Content')
->addLayout('Simple content section', 'wysiwyg', [
Text::make('Title'),
Markdown::make('Content')
])
->addLayout('Video section', 'video', [
Text::make('Title'),
Image::make('Video Thumbnail', 'thumbnail'),
Text::make('Video ID (YouTube)', 'video'),
Text::make('Video Caption', 'caption')
])
];
} Customizing the button labelYou can change the default "Add layout" button's text like so: Flexible::make('Content')
->button('Add something amazing!'); Using Flexible values in viewsIf you are using Laravel 6 and under, or don't want to use casts, please use an accessor on your model with the HasFlexible trait. Laravel 7 brings custom casts to the table, and flexible content fields are the perfect use case for them. The field stores its values as a single JSON string, meaning this string needs to be parsed before it can be used in your application. This can be done trivially by using the namespace App;
use Illuminate\Database\Eloquent\Model;
use Whitecube\NovaFlexibleContent\Value\FlexibleCast;
class MyModel extends Model
{
protected $casts = [
'flexible-content' => FlexibleCast::class
];
} By default, the Then easily map your custom layout classes to the proper keys: namespace App\Casts;
class MyFlexibleCast extends FlexibleCast
{
protected $layouts = [
'wysiwyg' => \App\Nova\Flexible\Layouts\WysiwygLayout::class,
'video' => \App\Nova\Flexible\Layouts\VideoLayout::class,
]
} If you need more control, you can override the The Layouts CollectionCollections returned by the The Layout instanceLayouts are some kind of fake models. They use Laravel's
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论