PHP code example of aichadigital / lara-content

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

    

aichadigital / lara-content example snippets


return [
    // Author model for posts (must have UUID v7 char(36) primary key)
    'author_model' => env('CONTENT_AUTHOR_MODEL', 'App\\Models\\User'),

    // Cache settings
    'cache' => [
        'enabled' => env('CONTENT_CACHE_ENABLED', true),
        'default_ttl' => env('CONTENT_CACHE_TTL', 3600),
    ],

    // Security: allowed HTML tags and attributes
    'security' => [
        'allowed_tags' => ['p', 'br', 'strong', 'em', 'a', 'img', ...],
        'allowed_attributes' => [...],
    ],
];

use AichaDigital\LaraContent\Models\Page;

// Create a page
$page = Page::create([
    'title' => 'About Us',
    'slug' => 'about-us',
    'layout' => 'sidebar-right',
    'status' => 'published',
]);

// Add blocks to zones
$page->blocks()->create([
    'zone' => 'main',
    'block_type' => 'html',
    'content' => ['html' => '<p>Welcome to our company...</p>'],
    'order' => 1,
]);

use AichaDigital\LaraContent\Enums\PublishStatus;
use AichaDigital\LaraContent\Models\Post;

$post = Post::create([
    'title' => 'Getting Started',
    'slug' => 'getting-started',
    'content' => '<p>Introduction...</p>',
    'author_id' => auth()->id(),
    'publish_status' => PublishStatus::PUBLISHED,
    'published_at' => now(),
]);

// Only PUBLISHED posts whose published_at is null or past are public.
$visible = Post::published()->get();

use AichaDigital\LaraContent\Models\Category;
use AichaDigital\LaraContent\Models\Tag;

$category = Category::create(['slug' => 'tips', 'name' => ['es' => 'Consejos', 'en' => 'Tips']]);
$tag = Tag::create(['slug' => 'grammar', 'name' => ['en' => 'Grammar']]);

$post->categories()->sync([$category->id]);
$post->tags()->sync([$tag->id]);

use AichaDigital\LaraContent\Models\Menu;

$menu = Menu::create([
    'name' => 'Main Navigation',
    'slug' => 'main-nav',
]);

$menu->items()->create([
    'title' => 'Home',
    'url' => '/',
    'order' => 1,
]);

use AichaDigital\LaraContent\Registries\LayoutRegistry;
use App\Content\Layouts\CustomLayout;

public function boot(): void
{
    app(LayoutRegistry::class)->register(new CustomLayout());
}

use AichaDigital\LaraContent\Registries\BlockRegistry;
use App\Content\Blocks\CustomBlock;

public function boot(): void
{
    app(BlockRegistry::class)->register(new CustomBlock());
}

use AichaDigital\LaraContent\Models\Page;

// Crear una página
$page = Page::create([
    'title' => 'Sobre Nosotros',
    'slug' => 'sobre-nosotros',
    'layout' => 'sidebar-right',
    'status' => 'published',
]);

// Añadir bloques a zonas
$page->blocks()->create([
    'zone' => 'main',
    'block_type' => 'html',
    'content' => ['html' => '<p>Bienvenido a nuestra empresa...</p>'],
    'order' => 1,
]);

use AichaDigital\LaraContent\Models\Post;

$post = Post::create([
    'title' => 'Primeros Pasos',
    'slug' => 'primeros-pasos',
    'content' => '# Introducción...',
    'author_id' => auth()->id(),
    'status' => 'published',
    'published_at' => now(),
]);

use AichaDigital\LaraContent\Models\Menu;

$menu = Menu::create([
    'name' => 'Navegación Principal',
    'slug' => 'nav-principal',
]);

$menu->items()->create([
    'title' => 'Inicio',
    'url' => '/',
    'order' => 1,
]);

use AichaDigital\LaraContent\Registries\LayoutRegistry;
use App\Content\Layouts\MiLayout;

public function boot(): void
{
    app(LayoutRegistry::class)->register(new MiLayout());
}

use AichaDigital\LaraContent\Registries\BlockRegistry;
use App\Content\Blocks\MiBloque;

public function boot(): void
{
    app(BlockRegistry::class)->register(new MiBloque());
}
bash
php artisan vendor:publish --tag="lara-content-migrations"
php artisan migrate
blade
@foreach($page->blocks as $block)
    {!! app(BlockRenderer::class)->render($block) !!}
@endforeach
bash
php artisan vendor:publish --tag="lara-content-migrations"
php artisan migrate