Flexible Fields for Laravel Nova
Published on by Eric L. Barnes
Flexible Fields is a Laravel Nova package that allows you to easily create repeatable fields or blocks within a resource. Check out this demo gif to get a better idea on how it works:
Flexible Fields allow you to use all the Laravel Nova field types, and also any community-made fields. So it's flexible enough to fit any setup you desire.
Once you have it installed you can add fields to your layouts like this:
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') ]) ];}
Which would display like this in your Nova admin:
A package like this gives you lots of power to create all sorts of dynamic content that you wouldn't otherwise be able to do easily. For more information on this package and to get started check out their official docs.
Eric is the creator of Laravel News and has been covering Laravel since 2012.