PHP code example of monstrex / voyager-site

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

    

monstrex / voyager-site example snippets


$mail = site_setting('mail.to_address');

str_trans('[[en]]Hello[[ru]]Privet');

namespace App\Http\Controllers;

use MonstreX\VoyagerSite\Traits\PageTrait;

class PagesController extends Controller
{
    use PageTrait;

    public function home()
    {

        $this->create('home');

        return $this->view();

    }
    
    public function show($alias)
    {

        $this->create($alias);

        return $this->view();

    }
    
    public function showArticle($alias)
    {

        $this->create($alias,'articles');

        return $this->view('layout.article', ['vars' => $some_vars]);

    }
}

namespace App\Http\Controllers;

use MonstreX\VoyagerSite\Traits\PageTrait;

use VSite, VPage, VData;

class PagesController extends Controller
{
    public function home()
    {

        VPage::create(VData::find('home'), VSite::getSettings());

        return VPage::view(); 

    }
}

$template            // Root template folder 
$template_master     // Master template name (to extend View)
$template_page       // Internal page template name
$breadcrumbs         // Breadcrumbs array
$title               // Page title
$banner              // Page banner image (if present)
$page                // Page instance
$parents             // Chain of parents of current page  
$children            // Children pages if present for current page
$data_sources        // Extra Data sources attached to the Page
$seo['title']        // Seo Title
$seo['description']  // Meta Description
$seo['keywords']     // Meta Keywords
$data                // Additional given data

public function service($alias)
{
    $pageContent = $this->create($alias,'services')->getContent();
    $this->setPageTemplate('pages.service');
    $this->buildBreadcrumbs();
    $this->setChildren('parent_id');
    return $this->view();
}

addBreadcrumbs(__('site.breadcrumb_home'), route(config('voyager-site.route_home_page')));

// Example (Additional Model properties)
public $masterPageRouteName = 'page';
public $masterPageSlug = 'pages';
public $masterPageId = 2;
public $pageRouteName = 'service';
public $bannerField = 'banner_image';



namespace App\Template;

class TemplateFilters
{
    public function handle($instance, $content)
    {
        $instance->registerFilter('div', function ($arg) {
            return '<div>' . $arg . '</div';
        });
    }
}

'sitemap' => [
    'enabled' => false,
    'cache_ttl' => 3600,
    'xclude_names' => [
        'debugbar.*',
    ],
    'routes' => [
        // Page model by slug
        'page.show' => [
            'model' => \MonstreX\VoyagerSite\Models\Page::class,
            'param' => 'slug',
            'field' => 'slug',
            'lastmod' => 'updated_at',
            'changefreq' => 'weekly',
            'priority' => 0.8,
        ],

        // Articles by slug with status filter
        'articles.show' => [
            'model' => \App\Models\Article::class,
            'param' => 'slug',
            'field' => 'slug',
            'status' => [
                'field' => 'status',
                'value' => [1],
            ],
            'lastmod' => 'updated_at',
            'changefreq' => 'weekly',
            'priority' => 0.6,
        ],

        // Routes with multiple parameters
        'catalog.product' => [
            'model' => \App\Models\Product::class,
            'params' => [
                'category' => 'category.slug',
                'product' => 'slug',
            ],
            'with' => ['category'],
            'lastmod' => 'updated_at',
        ],
    ],
    'static' => [
        '/' => ['priority' => 1.0, 'changefreq' => 'daily'],
        '/about' => ['priority' => 0.8, 'changefreq' => 'monthly'],
        '/contacts' => ['priority' => 0.7, 'changefreq' => 'monthly'],
    ],
    'defaults' => [
        'changefreq' => 'monthly',
        'priority' => 0.5,
    ],
],
 bash
$ php artisan voyager-site:install
bash
php artisan voyager-site:install --refresh
php artisan voyager-site:install --refresh --locale=ru

$ php artisan voyager-site:uninstall
html
{{ old }} <!-- Previous values saved in session = session()->getOldInput() -->
{{ errors_messages}} <!-- = $errors->all() -->
{{ errors }} <!-- = $errors->toArray() -->
{{ form_alias }} <!-- Form Key -->
{{ form_suffix }} <!-- Additional form suffix if you need -->
{{ form_subject }}} <!-- Form Subject -->
{{ csrf_token }} <!-- = csrf_token() -->

blade
{!! responsive_picture($page->image, 1200, 600, [
    'alt' => $page->title,
    'formats' => ['webp'],
    'breakpoints' => [
        ['media' => '(max-width: 768px)', 'width' => 600, 'height' => 300],
    ],
]) !!}
blade
{!! seo_tags($page) !!}