PHP code example of exeplor / ampere

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

    

exeplor / ampere example snippets


'providers' => [
    Illuminate\Validation\ValidationServiceProvider::class,
    Illuminate\View\ViewServiceProvider::class,
    // ...
    \Ampere\AmpereServiceProvider::class,
    // ...
];

return [

    /*
     * Main configuration
     */
    'app' => [

        /*
         * Ampere url path
         */
        'url_prefix' => 'myadminpanel',
    ],

    /*
     * Routing configuration
     */
    'routing' => [

        /*
         * Controllers folder
         */
        'folder' => 'app/Http/Controllers/Admin',

        /*
         * Controller namespace
         */
        'namespace' => 'App\Http\Controllers\Admin',

        /*
         * Space route prefix
         * Route space name
         */
        'prefix' => 'my.custom.name',
        // Example: route('my.custom.name.some.method')

        /*
         * Custom route group
         */
        'group' => [
            // If you have some specific middleware or other config
            // This place for Route::group() arguments
            'domain' => env('APP_DOMAIN')
        ]
    ],

    /*
     * Ampere DB configuration
     */
    'db' => [
        'prefix' => 'amp_'
    ],

    /*
     * Authorization config
     */
    'auth' => [

        /*
         * Captcha settings
         */
        'google_captcha' => [
            'enabled' => env('AMPERE_CAPTCHA_ENABLED', false),
            'site_key' => env('AMPERE_CAPTCHA_SITE_KEY'),
            'secret_key' => env('AMPERE_CAPTCHA_SECRET_KEY')
        ]
    ],

    /*
     * Installation settings
     */
    'install' => [
        /*
         * Ampere public assets folder
         */
        'assets_folder' => 'vendor/admin'
    ],

    /*
     * Views configuration
     */
    'views' => [
        'name' => 'admin'
    ]
];

/**
 * Class HomeController
 * @package App\Http\Controllers\Admin
 */
class HomeController extends Controller 
{
    /**
     * @return void
     */
    public function foo()
    {
        // Route result
        // GET /admin/home/foo
    }
    
    /**
     * @route bar
     */
    public function firstMethod()
    {
        // Result
        // GET /admin/home/bar
    }
    
    /**
     * @route entity/{id}
     */
    public function secondMethod(int $id)
    {
        // Result
        // GET /admin/home/entity/{$id}
    }
    
    /**
     * @route update/{id}
     * @post
     */
    public function thirdMethod(int $id)
    {
        // Result
        // POST /admin/home/update/{$id}
    }
    
    /**
     * @post secondMethod
     */
    public function fourthMethod(int $id)
    {
        // You can inherit route by method name in this controller
        // @post <controller_method_name>
        
        // Result
        // POST /admin/home/entity/{$id}
    }
    
    /**
     * @route some/route
     * @put
     */
    public function fifthMethod()
    {
        // Result
        // PUT /admin/home/some/route
    }
    
    /**
     * @route some/route
     * @delete
     */
    public function sixthMethod()
    {
        // Result
        // DELETE /admin/home/some/route
    }
}

$route = HomeController::route('secondMethod', [1]);
echo $route->route(); # return "ampere.home.someroutepath"
echo $route->url(); # return "home/entity/1"

if ($route->access()) {
    echo 'This route available for current user'; 
}

/**
 * Class HomeController
 * @package App\Http\Controllers\Admin
 */
class HomeController extends Controller
{
    /**
     * @route foo
     * @menu Home
     */
    public function home()
    {
        // Menu items:
        // Home > [link to "home/foo"]
    }
    
    /**
     * @menu Items > First
     */
    public function first()
    {
        // Menu items:
        // Home [link to "home/foo"]
        // Items
        //     First [link to "home/first"]
    }
    
    /**
     * @menu Items > Second
     */
    public function first()
    {
        // Menu items
        // Home [link to "home/foo"]
        // Items (submenu item)
        //     First [link to "home/first"]
        //     Second [link to "home/second"]
    }
}

public function home()
{
    return $this->render('home', ['value' => 'hello']);
}

use Ampere\Services\Grid\Grid;

/**
 * Class UsersController
 * @package App\Http\Controllers\Admin
 */
class UsersController extends Controller
{
    /**
     * @menu Users
     * @param Grid $grid
     */
    public function index(Grid $grid)
    {
        $grid
            ->column('id', '#')->strict()->sortable()->asc()
            ->column('name', 'Name')->search()
            ->column('email', 'Email')->search()
            ->column('is_active')->dropdown([
                0 => 'No',
                1 => 'Yes'
            ]);

        $grid->action('icon:flag-checkered')->success()->route(self::route('stats'), 'id');
        $grid->action('icon:pencil-alt')->primary()->route(self::route('edit'), 'id');
        $grid->action('icon:trash-alt', 'delete')->danger()->route(self::route('delete'), 'id');

        $grid->model(\App\Models\User::class)->limit(24)->search();
        return $this->render('users.index', ['mygrid' => $grid]);
    }
}

$grid
    ->column('id', '#')->sortable()->asc()
    ->column('role.title')->search()
    ->column('owner.email')->search()

$column = $grid->column('id', '#');
$column->strict(); // Strict search
$column->search(); // Default match search
$column->sortable(); // Column can by sortable
$column->asc(); // Default sort by ASC
$column->desc(); // Default sort by DESC
$column->date(); // Datetime range filtration

$column->dropdown([
    'first' => 'First value',
    'second' => 'Second value'
]); // Dropdown column type

$column->display(function($rowModel){
    return 'Display custom value ' . $rowModel->someValue;
});

$button = $grid->action('Edit');

// Colorize your button
$button->primary(); // Primary color
$button->success();  // Success color
$button->danger();  // Danger color

// Custom route
$button->route(function(\App\Models\User $user){
    return route('some.route.user', $user->id);
});

// Ampere route
$button->route('users.show', 'id'); // second argument

// Similarly
$button->route(SomeController::route('show'), 'id');

php artisan ampere:install

php artisan ampere:migrate

/resources/ampere/<ampere_space_name>/menu.php

php artisan am:crud Users/Permissions
html

    /**
     * @var \Ampere\Services\Workshop\Page\Layout $layout Layout configuration
     * @var \Ampere\Services\Workshop\Component $component Components manager
     * @var \Ampere\Services\Workshop\Page\Assets $

php artisan am:page mypage
html
<div class="ibox">
    <div class="ibox-body ibox-nopadding">
        @php($component->grid($data->mygrid))
    </div>
</div>