PHP code example of sirgrimorum / pages

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

    

sirgrimorum / pages example snippets


'with_routes' => true,   // Auto-register package routes
'localized'   => true,   // Prefix routes with locale: /{locale}/...
'group_name'  => 'paginas.',
'group_prefix' => '',    // Additional URL prefix

'extends' => 'layouts.app',  // Parent Blade layout
'content' => 'content',      // @section name for page content

'js_section'  => 'scripts',  // @push stack name for JS
'css_section' => 'styles',   // @push stack name for CSS

'paginas_policies' => [
    '_general' => fn() => true,                         // all pages (default)
    'admin*'   => fn() => Auth::user()?->isAdmin(),     // pages starting with "admin"
    '*private' => fn() => Auth::check(),                // pages ending with "private"
    '*secret*' => fn() => false,                        // pages containing "secret"
    'dashboard' => fn() => Auth::check(),               // exact match
],
'sections_policies' => [
    '_general' => fn() => true,
],

'special_sections' => [
    'featured_posts' => [
        'type'      => 'collection',             // 'simple', 'collection', or 'model'
        'isModel'   => App\Models\Post::class,
        'function'  => 'getFeatured',            // Method to call on the model
        'template'  => 'partials.featured_post', // Blade template for each item
    ],
    'site_notice' => [
        'type'     => 'simple',
        'template' => 'partials.site_notice',   // Just renders a Blade view
    ],
],

use Sirgrimorum\Pages\Pages;

// Inject all accessible pages into position 2 of the left nav
$menuConfig = Pages::getAutoMenuConfig(2, 'izquierdo', config('sirgrimorum/menus/main'));
echo AutoMenu::buildAutoMenu('main-nav', '', $menuConfig);

use Sirgrimorum\Pages\Pages;

if (Pages::hasAccessToPagina($page)) {
    // user can see this page
}

if (Pages::hasAccessToSection($section)) {
    // user can see this section
}

Pages::buildPage(
    mixed  $name   = '',  // Page name, ID, object, or '' for first allowed
    mixed  $config = '',  // Config array or path
    mixed  $sections = '' // Sections array override
): string

Pages::buildSection(mixed $name, mixed $config = ''): string

Pages::getFirstAllowedPage(): ?Pagina

Pages::getAutoMenuConfig(
    int    $offset,   // Position to insert pages in the menu array
    string $lado,     // Menu side: 'izquierdo' or 'derecha'
    array  $automenu  // Existing menu structure to inject into
): array
bash
php artisan migrate
bash
php artisan vendor:publish --provider="Sirgrimorum\Pages\PagesServiceProvider" --tag=config
bash
php artisan vendor:publish --provider="Sirgrimorum\Pages\PagesServiceProvider" --tag=lang
bash
php artisan vendor:publish --provider="Sirgrimorum\Pages\PagesServiceProvider" --tag=views
bash
php artisan pages:registercrud