tobento/app-backend

1.0.0 2025-06-04 15:58 UTC

This package is auto-updated.

Last update: 2025-06-04 16:07:21 UTC


README

The App Backend is a minimal admin panel using the following main app bundles:

Table of Contents

Getting Started

Add the latest version of the app backend project running this command.

composer require tobento/app-backend

Requirements

  • PHP 8.0 or greater

Documentation

App

Check out the App Skeleton if you are using the skeleton.

You may also check out the App to learn more about the app in general.

Backend Boot

The backend boot is extended :

use Tobento\App\AppFactory;

// Create the app
$app = (new AppFactory())->createApp();

// Add directories:
$app->dirs()
    ->dir(realpath(__DIR__.'/../'), 'root')
    ->dir(realpath(__DIR__.'/../app/'), 'app')
    ->dir($app->dir('app').'config', 'config', group: 'config')
    ->dir($app->dir('root').'public', 'public')
    ->dir($app->dir('root').'vendor', 'vendor');

// Adding boots
$app->boot(\Tobento\App\Backend\Boot\Backend::class);

// Run the app
$app->run();

Once booted, you can access the backend by the following URL http://localhost/{project}/public/admin/.

You may change the backend slug admin or even route to another domain in the app/config/apps.php file.

Adding Boots

There are two ways to add backend boots:

Via App Config

In the apps/backend/config/app.php file you can add more boots.

'boots' => [
    // ...
    SomeBoot::class,
],

Via Backend Boot

use Tobento\App\Boot;
use Tobento\App\Backend\Boot\Backend;

class BackendBoots extends Boot
{
    public const BOOT = [
        Backend::class,
    ];
    
    public function boot(Backend $backend): void
    {
        $backend->addBoot(SomeBoot::class);
    }
}

Register your boot:

use Tobento\App\AppFactory;

// Create the app
$app = (new AppFactory())->createApp();

// Add directories:
$app->dirs()
    ->dir(realpath(__DIR__.'/../'), 'root')
    ->dir(realpath(__DIR__.'/../app/'), 'app')
    ->dir($app->dir('app').'config', 'config', group: 'config')
    ->dir($app->dir('root').'public', 'public')
    ->dir($app->dir('root').'vendor', 'vendor');

// Adding boots
$app->boot(\Tobento\App\Backend\Boot\Backend::class);
$app->boot(BackendBoots::class);

// Run the app
$app->run();

Adding Dashboard Cards

Use the DashboardCards::class and app on method to add dashboard cards only on demand:

use Tobento\App\Backend\Card\DashboardCards;
use Tobento\App\Card\Factory;

$app->on(
    DashboardCards::class,
    static function(DashboardCards $cards): void {
        // Adding cards:
        $cards->add(name: 'foo', card: new Factory\Table(
            rows: ['foo', 'bar'],
        ));
    }
);

Check out the App Card bundle to learn more.

Adding Searchables

To add searchables, check out the App Search - Adding Searchables section.

Customization

Customize Via App

In your app/src directory you may create a boot customizing specific controllers for instance.

namespace App;

use use Tobento\App\Backend\Controller\RoleCrudController;

class Customization extends Boot
{
    public function boot(): void
    {
        // Custom controller:
        $this->app->set(RoleCrudController::class, \App\CustomRoleCrudController::class);
    }
}

In the apps/backend/config/app.php file add your boot.

'boots' => [
    // ...
    \App\Customization::class,
],

Customize Via App Config

In the apps/backend/config/app.php file you can replace existing boots with your customized boots.

'boots' => [
    // ...
    // Resources:
    //\Tobento\App\Backend\Boot\Roles::class,
    \Tobento\App\Backend\Boot\CustomRoles::class,
    //\Tobento\App\Backend\Boot\Users::class,
    \Tobento\App\Backend\Boot\CustomUsers::class,
    // ...
],

Testing

You may boot the \Tobento\App\Backend\Testing\UserAndRolesBoot::class which will migrate the following users for testing:

Email Smartphone Role Active
admin@example.com - administrator 1
inactive@example.com - administrator 0
editor@example.com 12345678 editor 1
registered@example.com - registered 1
use Tobento\App\AppInterface;

final class SomeBackendAppTest extends \Tobento\App\Testing\TestCase
{
    use \Tobento\App\Testing\Database\MigrateDatabases;
    
    public function createApp(): AppInterface
    {
        $app = $this->createTmpApp(rootDir: __DIR__.'/../..');
        $app->boot(\Tobento\App\Backend\Boot\Backend::class);
        $app->booting();
        
        $app = $app->get(AppsInterface::class)->get('backend')->app();
        $app->boot(\Tobento\App\Seeding\Boot\Seeding::class);
        $app->boot(\Tobento\App\Backend\Testing\UserAndRolesBoot::class);
        return $app;
    }
}

You may check out the following links to learn more about testing.

Credits