PHP code example of antonioprimera / laravel-site

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

    

antonioprimera / laravel-site example snippets


//gets the 'default' site
$site = site();

//gets the 'home' page of the 'default' site
$page = page('home');

//gets the 'hero' section of the 'home' page of the 'default' site
$section = section('home:hero');

//gets the 'cta' bit of the 'hero' section of the 'home' page of the 'default' site
$bit = bit('home:hero.cta');

//if you have several sites, you can specify the site key as the first argument for all the helpers
$bit = bit('my-site/home:hero.cta');

//setting the image of a section
section('home:hero')->setImageFromMediaCatalog('path/to/image.webp');

//retrieving the image of a section
$mediaInstance = section('home:hero')->image;

return [
    /**
     * The list of locales that should be used for translations
     * Make sure to  //the string that should be displayed if a translation is missing
    ],

    /**
     * Site section view component default configuration
     */
    'sections' => [

        //section images will be resized to fit these dimensions
        'image' => [
            'max-width' => 1920,
            'max-height' => 1080,
        ],
    ],

    /**
     * Data migrations configuration
     */
    'data-migrations' => [

        //the path to the directory where site data migrations are stored, relative to the database directory
        'path' => 'site-migrations',
    ],

    'model-builders' => [
        //whether the model builders should automatically save the model after each fluent method call
        //e.g. calling $builder->withName('test') will automatically save the model if this is set to true
        'fluent-auto-save' => true,
    ],

    /**
     * Media catalog configuration
     */
    'media-catalog' => [
        //the disk where media catalog files are stored
        'disk' => 'media-catalog',
    ],

    'views' => [
        //the root path for the blade views of the site components (relative to the resources/views directory)
        'bladeRootName' => 'components',

        //the namespace of the site components
        'componentNamespace' => 'App\\View\\Components\\',
    ],

    //settings for the generator commands: site:page, site:section, site:bit
    'generator-command' => [
        'pages' => [
            'rootNamespace' => 'App\\View\\Components\\Pages',
            'classTargetFolder' => 'View/Components/Pages',         //relative to the project root
            'bladeTargetFolder' => 'components/pages',              //relative to the resources/views directory
        ],

        'sections' => [
            'rootNamespace' => 'App\\View\\Components\\Sections',
            'classTargetFolder' => 'View/Components/Sections',
            'bladeTargetFolder' => 'components/sections',
        ],

        'bits' => [
            'rootNamespace' => 'App\\View\\Components\\Bits',
            'classTargetFolder' => 'View/Components/Bits',
            'bladeTargetFolder' => 'components/bits',
        ],
    ]
];

use AntonioPrimera\Site\Database\DataMigration;
use AntonioPrimera\Site\Database\ModelBuilders\SiteBuilder;
use AntonioPrimera\Site\Database\ModelBuilders\PageBuilder;
use AntonioPrimera\Site\Database\ModelBuilders\SectionBuilder;
use AntonioPrimera\Site\Database\ModelBuilders\BitBuilder;

return new class extends DataMigration {

    public function up(): void
    {
        //if this is the first migration, you should create the site first
        SiteBuilder::create('default', 'My Personal Branding Site')
            ->withData([
                'logo' => 'path/to/logo.webp',
                'favicon' => 'path/to/favicon.webp',
                'socialMedia' => [
                    'facebook' => 'https://facebook.com/my-profile',
                    'instagram' => 'https://instagram.com/my-profile',
                    'x' => 'https://x.com/my-profile',
                ],
            ]);
        
        //create the home page
        PageBuilder::create(
            uid: 'home',
            name: 'Home Page',
            title: 'My Home Page',
            short: 'This is my presentation home page',
            route: 'home',
            menuLabel: 'Home',
            menuVisible: true,
            menuPosition: 1,
            data: [
                'seo' => [
                    'title' => 'My Home Page',
                    'description' => 'This is the description of my home page',
                    'keywords' => 'home, page, website',
                ],
            ]
        );
        
        SectionBuilder::create(page: 'home', uid: 'hero', name: 'Home Hero Section')
            ->withTitle(['en' => 'Welcome to our website', 'de' => 'Willkommen auf unserer Webseite'])
            ->withContents(['en' => 'This is the hero section of the home page', 'de' => 'Dies ist der Hero-Bereich der Startseite'])
            ->withImageFromMediaCatalog('path/to/home-hero-image.webp')
            ->createBit(
                uid: 'cta',
                title: ['en' => 'Contact us', 'de' => 'Kontaktiere uns'],
                data: ['url' => '/contact', 'icon' => 'heroicon-o-phone'],
                build: fn(BitBuilder $builder) =>
                    $builder->withImageFromMediaCatalog('path/to/cta-background-image.webp', 'cta image alt text')
            )
            ->createBit(
                uid: 'motto',
                build: fn(BitBuilder $builder) =>
                    $builder->withTitle(['en' => 'Our Motto', 'de' => 'Unser Motto'])
                        ->withContents(['en' => 'This is our motto', 'de' => 'Das ist unser Motto'])
                        ->withImageFromMediaCatalog('path/to/motto-side-image.webp', 'our motto image alt text')
            );
    }

    public function down(): void
    {
        SectionBuilder::delete('home:hero');
    }
};
bash
php artisan vendor:publish --tag="site-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="site-config"
bash
php artisan site:migration CreateHomePage