PHP code example of think.studio / nova-flexible-content
1. Go to this page and download the library: Download think.studio/nova-flexible-content library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
think.studio / nova-flexible-content example snippets
namespace App\Nova\Flexible\Layouts;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\Markdown;
use NovaFlexibleContent\Layouts\Layout;
class VideoLayout extends Layout
{
// Optionally you limit count of this layout in flexible groups
// protected int $limit = 3;
protected function linksPreset()
{
return Preset::withLayouts([
LinkLayout::class,
]);
}
/**
* Get the fields displayed by the layout.
*/
public function fields(): array
{
return [
Text::make('Title', 'title')
->help('Optional'),
FileForFlexible::make('Video', 'video')
->prunable()
->acceptedTypes('video/mp4')
->deletable()
->help('Aspect ratio 16:9. Please do not upload a large file.'),
ImageForFlexible::make('Poster', 'poster')
->prunable()
->rules(['max:' . 1024 * 10])
->deletable()
->help('Aspect ratio 16:9.'),
// Recursive flexible
\NovaFlexibleContent\Flexible::make('Links', 'links')
->preset($this->linksPreset())
->layoutsMenuButton('Add link'),
];
}
}
namespace App\Nova\Flexible\Resolvers;
use NovaFlexibleContent\Layouts\Collections\GroupsCollection;
use NovaFlexibleContent\Layouts\Collections\LayoutsCollection;
use NovaFlexibleContent\Value\Resolver;
class WysiwygPageResolver implements Resolver
{
public function get(mixed $resource, string $attribute, LayoutsCollection $groups): GroupsCollection
{
return new GroupsCollection();
}
public function set(mixed $resource, string $attribute, GroupsCollection $groups): string
{
return '';
}
}
namespace App;
use Illuminate\Database\Eloquent\Model;
use NovaFlexibleContent\Concerns\HasFlexible;
class Post extends Model
{
use HasFlexible;
// Collect basic `Layout` instances
public function getCollectedFlexibleContentAttribute()
{
return $this->flexible('flexible-content');
}
// Cast to specified classes
public function getCastedFlexibleContentAttribute()
{
return $this->flexible('flexible-content', [
'wysiwyg' => \App\Nova\Flexible\Layouts\WysiwygLayout::class,
'video' => \App\Nova\Flexible\Layouts\VideoLayout::class,
]);
}
}