PHP code example of pvtl / dynamic-content

1. Go to this page and download the library: Download pvtl/dynamic-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/ */

    

pvtl / dynamic-content example snippets


return [
    // Filesystem disk for section image/file uploads.
    'disk' => env('DYNAMIC_CONTENT_DISK', 'public'),

    // Layout component used by the editor preview (<x-layouts.public>).
    'preview_layout' => 'layouts.public',

    // Blade component directory for frontend section renderers.
    // 'dynamic' resolves a section component named 'homepage-hero'
    // to <x-dynamic.homepage-hero>.
    'component_directory' => env('DYNAMIC_CONTENT_COMPONENT_DIR', 'dynamic'),
];

use Pvtl\DynamicContent\Enums\SectionFieldType;

return [
    [
        'slug'        => 'homepage-hero',
        'component'   => 'homepage-hero',
        'description' => 'Hero banner displayed at the top of the homepage.',
        'fields'      => [
            [
                'name'       => 'Heading',
                'slug'       => 'heading',
                'description'=> 'Main headline text.',
                'type'       => SectionFieldType::Text,
                'class'      => 'w-1/2',
                'default'    => '',
                'validation' => ['

// ❌ Don't do this — crashes the app.
'options' => \App\Models\Meal::all()->mapWithKeys(fn ($meal) => [$meal->id => $meal->name]),

// app/Models/Meal.php
public static function dynamicContentOptions(): array
{
    return static::query()->orderBy('name')->pluck('name', 'id')->all();
}

// config/sections.php
[
    'name'       => 'Featured Meal',
    'slug'       => 'featured_meal',
    'description'=> 'Meal to highlight in this section.',
    'type'       => SectionFieldType::Select,
    'class'      => 'w-1/2',
    'default'    => null,
    'validation' => ['nullable'],
    'options'    => [\App\Models\Meal::class, 'dynamicContentOptions'],
],
css
@source '../../vendor/pvtl/dynamic-content/resources/views/**/*.blade.php';
bash
php artisan pvtl-dynamic-content:publish
php artisan migrate
bash
php artisan pvtl-dynamic-content:publish-sections