PHP code example of rynbd / lyrapanel

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

    

rynbd / lyrapanel example snippets


use Rynbd\LyraPanel\Traits\HasRoles;
use Rynbd\LyraPanel\Traits\HasPrivileges;
use Rynbd\LyraPanel\Traits\HasSuspension;

class User extends Authenticatable
{
    use HasRoles, HasPrivileges, HasSuspension;
}

return [
    'routes' => [
        'prefix' => 'panel',           // URL prefix
        'middleware' => ['web', 'auth'], // Applied middleware
        'admin_middleware' => ['role:admin'], // Admin-only middleware
    ],
    'pagination' => ['per_page' => 15],
    'audit' => ['enabled' => true],
    'impersonation' => ['enabled' => true],
    'invitations' => ['enabled' => true],
    'branding' => [
        'name' => 'LyraPanel',
        'logo' => null,
    ],
    // ...more options
];

// Assign roles
$user->assignRole('admin');
$user->assignRole('editor');

// Check roles
$user->hasRole('admin');         // true
$user->hasAnyRole(['admin', 'editor']); // true

// Check privileges (through roles)
$user->hasPrivilege('users.create');
$user->can('posts.edit');        // alias for hasPrivilege

// In routes
Route::middleware('role:admin')->group(function () {
    // Admin-only routes
});

Route::middleware('privilege:posts.create')->group(function () {
    // Routes requiring specific privilege
});

Route::middleware('not-suspended')->group(function () {
    // Block suspended users
});

use Rynbd\LyraPanel\Traits\HasDynamicCrud;

class Post extends Model
{
    use HasDynamicCrud;

    public static function crudFields(): array
    {
        return [
            'title' => [
                'type' => 'text',
                'label' => 'Title',
                'rules' => 'st' => false,
                'form' => true,
            ],
            'status' => [
                'type' => 'select',
                'label' => 'Status',
                'options' => ['draft' => 'Draft', 'published' => 'Published'],
                'rules' => '

'resources' => [
    'posts' => [
        'model' => \App\Models\Post::class,
        'label' => 'Posts',
        'icon' => 'document',
    ],
],

// Suspend a user
$user->suspend('Violation of terms', now()->addDays(7));

// Unsuspend
$user->unsuspend();

// Check status
$user->isSuspended(); // bool

use Rynbd\LyraPanel\Support\AuditLogger;

// Manual logging
AuditLogger::log('custom_action', $model, 'Description of what happened');

// With old/new values
AuditLogger::logUpdate($model, $oldValues, $newValues);
bash
php artisan lyra:install
bash
# Publish config
php artisan vendor:publish --tag=lyrapanel-config

# Publish migrations
php artisan vendor:publish --tag=lyrapanel-migrations

# Run migrations
php artisan migrate
bash
php artisan vendor:publish --tag=lyrapanel-views