PHP code example of mylaraveltools / panel

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

    

mylaraveltools / panel example snippets


// app/Panel/Resources/ProductResource.php
final class ProductResource extends Resource
{
    protected static string $model = Product::class;
    protected static ?string $label = 'Productos';
    protected static ?string $icon = 'package';

    public static function form(): array
    {
        return [
            TextField::make('name')->label('Nombre')->

'theme' => [
    'default' => 'dark',
    'font' => 'Plus Jakarta Sans',
    'colors' => [
        'primary' => '#000000',
        'primary_dark' => '#ffffff',
        'accent' => '#525252',
        'success' => '#16a34a',
        'danger' => '#dc2626',
        'warning' => '#ca8a04',
    ],
    'light' => [ /* bg, surface, card, border, heading, text, muted… */ ],
    'dark' => [ /* … */ ],
],

// config/panel.php
'default' => 'admin',
'panels' => [
    'admin' => 

'theme' => [
    'preset' => 'corporate',  // minimal | corporate | contrast | ocean
    'colors' => [
        'primary' => '#ff0000',  // sobrescribe solo el preset
    ],
],

'extensions' => [
    'field_views' => ['rating' => 'panel-custom.fields.rating'],
    'column_views' => ['rating' => 'panel-custom.columns.rating'],
    'widgets' => [],
],

use MyLaravelTools\Panel\Facades\PanelExtensions;

PanelExtensions::registrarVistaCampo('rating', 'panel-custom.fields.rating');
PanelExtensions::registrarWidget(StatWidget::make('Total', fn () => Model::count()));

CustomField::make('payload')
    ->type('json-editor')
    ->view('panel-custom.fields.json-editor')
    ->label('Datos JSON'),

'layout' => [
    'density' => 'compact',           // comfortable | compact
    'content_width' => 'boxed',       // full | boxed
    'sidebar_collapsible' => true,
    'show_breadcrumbs' => true,
    'footer_links' => [
        ['label' => 'Ayuda', 'route' => 'panel.dashboard'],
        ['label' => 'Web', 'url' => 'https://ejemplo.com', 'external' => true],
    ],
],

'brand' => [
    'name' => 'Mi Panel',
    'logo' => '/img/logo.svg',
    'logo_height' => '2.5rem',
    'favicon' => '/favicon.ico',
    'tagline' => 'Gestiona tu negocio',
],

'auth_ui' => [
    'layout' => 'split',              // centered | split
    'image' => '/img/auth-side.jpg',
    'background' => 'linear-gradient(135deg, #0f172a, #1e3a5f)',
    'show_tagline' => true,
],

'customization' => [
    'css' => '.panel-sidebar { border-right-width: 2px; }',
    'head_view' => 'panel-custom.head',
],

RepeaterField::make('lineas')
    ->columns(['concepto' => 'Concepto', 'importe' => 'Importe'])
    ->minRows(1)
    ->maxRows(10),

'layout' => [
    'mode' => 'sidebar',              // sidebar | topbar | dual
    'sidebar_position' => 'left',     // left | right
    'table_striped' => true,
    'table_compact' => false,
    'global_search' => true,
    'per_page_options' => [15, 25, 50, 100],
],

'slots' => [
    'sidebar.before' => 'mi-app.panel.slots.aviso',
    'main.after' => 'mi-app.panel.slots.analytics',
    'topbar.end' => 'mi-app.panel.slots.acciones',
],

use MyLaravelTools\Panel\Support\PanelExtensions;

PanelExtensions::registrarSlot('main.before', 'mi-app.panel.banner');

'import' => [
    'upsert' => true,
    'upsert_key' => 'email',          // global; el Resource puede sobreescribir
],

// En tu Resource
public static function importUpsertKey(): ?string
{
    return 'sku';
}

public static function navigationBadge(): ?string
{
    return (string) static::model()::where('is_active', false)->count();
}

public static function hiddenFromNavigation(): bool
{
    return ! auth()->user()?->can('view settings');
}

public static function perPageOptions(): array
{
    return [10, 25, 50];
}

'theme' => [
    'preset' => 'mi-marca',
    'presets_file' => config_path('panel-theme-presets.php'),
],

'auth' => [
    'enabled' => true,
    'register' => true,
    'register_role' => 'viewer',      // Spatie, opcional
    'password_reset' => true,
    'email_verification' => false,    // requiere MustVerifyEmail
],

'permissions' => [
    'enabled' => true,
    'panel_access' => 'access panel',
    'resources' => true,              // RoleResource + PermissionResource
    'manage_permission' => 'manage users',
],

'impersonation' => [
    'enabled' => true,
    'permission' => 'impersonate users',
    'exclude_ids' => [],
    'banner' => true,
],

// config/panel.php
'navigation' => 

return [
    ['resource' => ProductResource::class],
    ['page' => SettingsPage::class],
    [
        'type' => 'group',
        'label' => 'Catálogo',
        'icon' => 'package',
        'children' => [
            ['resource' => ProductResource::class],
            ['resource' => CategoryResource::class],
        ],
    ],
];

final class SettingsPage extends Page
{
    protected static ?string $label = 'General';
    protected static ?string $slug = 'settings-general';

    public static function view(): string
    {
        return 'panel.pages.settings-general';
    }
}

'import' => [
    'enabled' => true,
    'preview' => true,
    'upsert' => true,
    'upsert_key' => null,
],

'widgets' => [
    ResourceCountWidget::make(ProductResource::class),
    StatWidget::make('Activos', fn () => Product::where('is_active', true)->count())
        ->icon('check-circle'),
    ChartWidget::make('Ventas', 'bar', fn () => [
        'labels' => ['Ene', 'Feb'],
        'values' => [12, 19],
    ])->themeColors(),
    ViewWidget::make('Custom', 'panel.widgets.mi-vista', fn () => ['total' => 100])
        ->columnSpan(2),
],

public static function relations(): array
{
    return [
        RelationManager::make('products', ProductResource::class),
        RelationManager::hasOne('profile', ProfileResource::class),
        RelationManager::belongsToMany('tags', TagResource::class),
        RelationManager::morphMany('reviews', ReviewResource::class),
        RelationManager::morphToMany('tags', TagResource::class),
    ];
}
bash
php artisan panel:install
js
export default {
  darkMode: 'class',
  content: [
    './resources/views/**/*.blade.php',
    './vendor/mylaraveltools/panel/resources/views/**/*.blade.php',
  ],
};
bash
npm run build
php artisan serve
bash
php artisan panel:make-resource Product --model=Product
bash
php artisan panel:upgrade-views --dry-run
php artisan panel:upgrade-views --force
bash
php artisan panel:upgrade-config --dry-run
php artisan panel:upgrade-config
php artisan panel:doctor
bash
php artisan panel:install --demo
bash
php artisan panel:make-page Settings
bash
php artisan vendor:publish --tag=panel-views --force
php artisan view:clear
bash
cd panel-demo
composer install && npm install && npm run build
php artisan migrate:fresh --seed
php artisan serve