PHP code example of oi-lab / oi-laravel-publish

1. Go to this page and download the library: Download oi-lab/oi-laravel-publish 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/ */

    

oi-lab / oi-laravel-publish example snippets


use OiLab\OiLaravelPublish\Models\PublishPage;
use OiLab\OiLaravelPublish\Models\PublishBlock;

$home = PublishPage::create([
    'template_key' => 'landing',
    'name'         => 'Home',
    'slug'         => 'home',
]);

$about = PublishPage::create([
    'parent_id'    => $home->id,
    'template_key' => 'default',
    'name'         => 'About',
    'slug'         => 'about',   // unique per parent
]);

$hero = PublishBlock::create([
    'publish_page_id' => $home->id,
    'template_key'    => 'hero',
    'name'            => 'Hero',
    'key'             => 'hero',
    'props'           => ['heading' => 'Welcome', 'alignment' => 'center'],
]);

$home->blocks;            // ordered by `sort`
$hero->props->heading;    // 'Welcome' (typed HeroData)
$hero->template();        // PublishTemplateData

$home->attachFile($file, 'cover');
$hero->syncAttachments([$slideA, $slideB], 'slides');

use OiLab\OiLaravelPublish\OiLaravelPublish;

OiLaravelPublish::pageModel();
OiLaravelPublish::template('hero');
OiLaravelPublish::blockTemplates();

use OiLab\OiLaravelPublish\Data\PublishTemplateData;
use OiLab\OiLaravelPublish\Enums\PublishTemplateType;
use OiLab\OiLaravelPublish\OiLaravelPublish;

OiLaravelPublish::registry()->register(new PublishTemplateData(
    key: 'pricing',
    name: 'Pricing table',
    type: PublishTemplateType::Block,
    propsClass: \App\Publish\PricingData::class,
));
bash
php artisan vendor:publish --tag=oi-laravel-publish-migrations
php artisan migrate
bash
php artisan vendor:publish --tag=oi-laravel-publish-config
bash
php artisan publish:install-settings
bash
php artisan oi:install-ai-skill