1. Go to this page and download the library: Download juneszh/alight-admin 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/ */
juneszh / alight-admin example snippets
declare(strict_types=1);
namespace ctr\admin;
use Alight\Admin\Auth;
use Alight\Admin\Form;
use Alight\Admin\Table;
class Test
{
public static function userTable(): void
{
// Check the role_id from logged in user
Auth::checkRole([1]); // Here '1' means only administrators have access
// Create the table columns and search bar
Table::column('id')->sort('ascend');
Table::column('account')->search()->sort();
Table::column('role_id')->search('select')->enum([1 => 'Administrator', 2 => 'Editor']);
Table::column('name')->search();
Table::column('email')->search();
Table::column('status')->search('select')->enum([1 => 'Enable', 2 => 'Disable']);
Table::column('create_time')->search('dateRange');
// Create the buttons
Table::button('add')->toolbar(); // Here 'toolbar()' means this button will be placed on toolbar
Table::button('edit');
Table::button('password')->color(Table::COLOR_DANGER);
// Bind the database table 'admin_user' and render table page
Table::render('admin_user');
}
}
public static function userForm(): void
{
// Ditto, Check the user access
Auth::checkRole([1]);
// Create the form fields
Form::create('add'); // This form will bind the 'add' button
Form::field('account')-> Form::field('confirm_password')->database(false)->type('password')-> // Create last form for 'password' button
Form::create('password')->copy('add', ['password', 'confirm_password']);
// Bind the database table 'admin_user' and render form page
Form::render('admin_user');
}
declare(strict_types=1);
use Alight\Route;
Route::get('test/user/table', [\ctr\admin\Test::class, 'userTable'])->auth();
Route::any('test/user/form', [\ctr\admin\Test::class, 'userForm'])->auth();
declare(strict_types=1);
use Alight\Admin\Menu;
Menu::item('Test');
Menu::subItem('User')->url('test/user/table');
declare(strict_types=1);
use Alight\Admin\Console;
// Here using Line charts, we support 30+ charts with AntDesign Charts
// More details please refer to : https://ant-design-charts.antgroup.com/en/examples
Console::chart(Console::CHART_LINE)->config([
'xField' => 'date',
'yField' => 'value',
'height' => 200,
'data' => [
['date' => '2019-07-21', 'value' => 20],
['date' => '2019-07-22', 'value' => 14],
['date' => '2019-07-23', 'value' => 9],
['date' => '2019-07-24', 'value' => 26]
]
])->grid(['span' => 12]); // Means half the width of the grid. full of 24
declare(strict_types=1);
use Alight\Admin\Console;
Console::chart(Console::CHART_COLUMN)->config([
'xField' => 'date',
'yField' => 'value',
'height' => 200
])->grid(['span' => 12])->api('test/column'); // Define the path to the API
public static function columnData(): void
{
// Check the user access
Auth::checkRole([1]);
$data = [
['date' => '2019-08-28', 'value' => 20],
['date' => '2019-08-29', 'value' => 19],
['date' => '2019-08-30', 'value' => 6],
['date' => '2019-08-31', 'value' => 9]
];
// Response using the built-in json format api
\Alight\Response::api(0, null, ['data' => $data]);
}
declare(strict_types=1);
use Alight\Route;
Route::get('test/column', [\ctr\admin\Test::class, 'columnData'])->auth();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.