### Finalize Laravel Admin Installation Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/installation.md Run this command to complete the Laravel Admin setup, which typically involves database migrations and other final configurations. After this, you can access the admin panel at `http://localhost/admin/`. ```Shell php artisan admin:install ``` -------------------------------- ### Publish Laravel Admin Vendor Assets and Configuration Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/installation.md Execute this command to publish Laravel Admin's assets and configuration file (`config/admin.php`). The configuration file allows customization of the installation directory, database connection, and table names. ```Shell php artisan vendor:publish --provider="Encore\Admin\AdminServiceProvider" ``` -------------------------------- ### Install Laravel Admin Package via Composer Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/installation.md This command adds the `encore/laravel-admin` package to your project's dependencies. It requires PHP 7+ and Laravel 5.5+. ```Shell composer require encore/laravel-admin "1.5.*" ``` -------------------------------- ### Install Laravel Admin Package Source: https://github.com/z-song/laravel-admin/blob/master/README.md This snippet provides the necessary command-line steps to install the Laravel Admin package, publish its assets and configuration files, and finalize the setup. It requires PHP 7+ and Laravel 5.5+. ```Bash composer require encore/laravel-admin php artisan vendor:publish --provider="Encore\Admin\AdminServiceProvider" php artisan admin:install ``` -------------------------------- ### SQL Schema for Laravel Users Table Source: https://github.com/z-song/laravel-admin/blob/master/docs/zh/quick-start.md Defines the database table structure for the `users` table, including columns for ID, name, email, password, tokens, and timestamps, with primary and unique keys for efficient data management. ```SQL CREATE TABLE `users` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `email` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `password` varchar(60) COLLATE utf8_unicode_ci NOT NULL, `remember_token` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (`id`), UNIQUE KEY `users_email_unique` (`email`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ``` -------------------------------- ### Configure Laravel Admin Resource Route Source: https://github.com/z-song/laravel-admin/blob/master/docs/zh/quick-start.md Adds a resource route for 'users' to the `app/Admin/routes.php` file. This configuration links the 'users' URI to the `UserController::class`, enabling automatic routing for standard CRUD operations. ```PHP $router->resource('users', UserController::class); ``` -------------------------------- ### Generate Laravel Admin Controller with Artisan Source: https://github.com/z-song/laravel-admin/blob/master/docs/zh/quick-start.md Uses the `php artisan admin:make` command to create a new controller (`UserController`) linked to the `App\User` model. This command automates the creation of the controller file, preparing it for CRUD operations. A specific note is included for Windows users regarding path separators. ```PHP php artisan admin:make UserController --model=App\\User // 在windows系统中 php artisan admin:make UserController --model=App\User ``` -------------------------------- ### Define `users` Table Schema for Laravel Admin Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/quick-start.md This SQL snippet defines the `users` table schema, which is used as an example in Laravel Admin. It includes standard fields like `id`, `name`, `email`, `password`, and timestamps, along with primary and unique keys, suitable for a typical user management system. ```sql CREATE TABLE `users` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `email` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `password` varchar(60) COLLATE utf8_unicode_ci NOT NULL, `remember_token` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (`id`), UNIQUE KEY `users_email_unique` (`email`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ``` -------------------------------- ### Laravel Admin Generated File Structure Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/installation.md Upon successful installation, Laravel Admin creates the `app/Admin` directory. This directory houses controllers, a bootstrap file, and route definitions, serving as the primary location for admin panel development. ```Shell app/Admin ├── Controllers │   ├── ExampleController.php │   └── HomeController.php ├── bootstrap.php └── routes.php ``` -------------------------------- ### Install Laravel Admin Helpers Extension Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/extension-helpers.md This snippet provides the necessary Composer command to install the `laravel-admin-ext/helpers` package and the Artisan command to import its assets into your Laravel Admin project. Ensure proper file and directory permissions to avoid errors during installation. ```php composer require laravel-admin-ext/helpers php artisan admin:import helpers ``` -------------------------------- ### Install Laravel Admin API Tester Package Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/extension-api-tester.md Installs the `laravel-admin-ext/api-tester` package into your Laravel project using Composer. The `-vvv` flag enables verbose output during the installation process. ```shell $ composer require laravel-admin-ext/api-tester -vvv ``` -------------------------------- ### Register Laravel Admin Resource Route for Users Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/quick-start.md This PHP code snippet registers a resource route for the `UserController` within the Laravel Admin routing file (`app/Admin/routes.php`). This route enables standard CRUD operations for the `demo/users` path, linking it to the generated controller and making the interface accessible. ```php $router->resource('demo/users', UserController::class); ``` -------------------------------- ### Generate Laravel Admin Controller for User Model Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/quick-start.md This command generates a new Laravel Admin controller (`UserController`) linked to the `App\User` model. It creates the controller file in `app/Admin/Controllers/` and is essential for defining the grid and form logic. A specific command is provided for Windows users due to backslash escaping requirements. ```php php artisan admin:make UserController --model=App\\User // under windows use: php artisan admin:make UserController --model=App\User ``` -------------------------------- ### Add Laravel Admin Menu Title Translation Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/quick-start.md This example demonstrates how to add a translated menu title to a Laravel language file, specifically for Laravel Admin menus. The key should be lowercase with spaces replaced by underscores, and the value is the translated string, allowing for multi-language support in the admin panel's navigation. ```php ... // lowercase and replace spaces with _ 'menu_titles' => [ 'work_units' => 'Unidades de trabajo' ], ``` -------------------------------- ### Define a Basic GET API Route in Laravel Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/extension-api-tester.md Demonstrates how to add a simple GET route to your `routes/api.php` file. This route returns a basic 'hello world' string, serving as a fundamental endpoint for initial testing with the API tester. ```php Route::get('test', function () { return 'hello world'; }); ``` -------------------------------- ### Translate Laravel Admin Menu Title Source: https://github.com/z-song/laravel-admin/blob/master/docs/zh/quick-start.md Demonstrates how to add a menu title translation in a Laravel language file (e.g., `resources/lang/es/admin.php`). It shows mapping a snake_case key to a human-readable string, specifically for 'work units', to localize menu entries. ```PHP ... // 用_小写并用_替换空格 'menu_titles' => [ 'work_units' => 'Unidades de trabajo' ], ``` -------------------------------- ### Complete Laravel Admin Installation Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/README.md This final Artisan command completes the `laravel-admin` setup process, which typically involves migrating database tables and setting up default user accounts. After successful execution, the admin panel will be accessible via `http://localhost/admin/` with default credentials (admin/admin). ```PHP php artisan admin:install ``` -------------------------------- ### Install Laravel Admin Scheduling Extension with Composer Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/extension-scheduling.md This snippet provides the necessary shell commands to install the `laravel-admin-ext/scheduling` package using Composer. After installation, it imports the required assets into the Laravel Admin panel, making the web interface accessible. ```bash $ composer require laravel-admin-ext/scheduling -vvv $ php artisan admin:import scheduling ``` -------------------------------- ### Install Laravel Admin Config Extension Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/extension-config.md Commands to install the Laravel Admin configuration extension via Composer and run database migrations, setting up the necessary database tables. ```Shell $ composer require laravel-admin-ext/config $ php artisan migrate ``` -------------------------------- ### Install Laravel Admin Package via Composer Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/README.md This command installs the `encore/laravel-admin` package, specifically version 1.5.*, using Composer. It's the initial step to integrate the administrative interface builder into your Laravel project. Ensure you have Laravel 5.5+ and PHP 7+ installed. ```Bash composer require encore/laravel-admin 1.5.* ``` -------------------------------- ### Install Laravel Admin Media Manager Extension Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/extension-media-manager.md This snippet provides the commands to install the media manager extension for Laravel Admin using Composer and import its assets into the application. ```Shell $ composer require laravel-admin-ext/media-manager -vvv $ php artisan admin:import media-manager ``` -------------------------------- ### Install Laravel-Excel for Data Export Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/model-grid-export.md This snippet shows the shell commands to install the Laravel-Excel library via Composer and publish its vendor assets, which is a prerequisite for custom Excel exports in Laravel Admin. ```shell composer require maatwebsite/excel:~2.1.0 php artisan vendor:publish --provider="Maatwebsite\Excel\ExcelServiceProvider" ``` -------------------------------- ### Configuring Qiniu Cloud Storage Disk for Laravel Admin Uploads Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/model-form-upload.md Provides an example of adding a 'qiniu' disk configuration in `config/filesystems.php` for integrating Qiniu cloud storage. This includes essential settings like domains, access keys, secret keys, and bucket information required for successful cloud uploads. ```php 'disks' => [ ... , 'qiniu' => [ 'driver' => 'qiniu', 'domains' => [ 'default' => 'xxxxx.com1.z0.glb.clouddn.com', 'https' => 'dn-yourdomain.qbox.me', 'custom' => 'static.abc.com' ], 'access_key'=> '', //AccessKey 'secret_key'=> '', //SecretKey 'bucket' => '', //Bucket 'notify_url'=> '', // 'url' => 'http://of8kfibjo.bkt.clouddn.com/' ] ], ``` -------------------------------- ### PHP Model for Model-Tree (Basic) Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/model-tree.md Illustrates the basic PHP model setup for `model-tree`, extending `Illuminate\Database\Eloquent\Model` and using the `Encore\Admin\Traits\ModelTree` trait. It specifies the table name `demo_categories`. ```php all(); }); ``` -------------------------------- ### Create 'movies' Table SQL Source: https://github.com/z-song/laravel-admin/blob/master/docs/zh/model-grid.md SQL DDL to create the `movies` table, including columns for title, director, description, rate, release status, and timestamps. This table serves as the data source for the Laravel Admin grid example. ```sql CREATE TABLE `movies` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `title` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `director` int(10) unsigned NOT NULL, `describe` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `rate` tinyint unsigned NOT NULL, `released` enum(0, 1), `release_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; ``` -------------------------------- ### Apply Permission Middleware to Routes Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/permission.md This example demonstrates how to use the `admin.permission` middleware to control access to route groups. It shows three common scenarios: allowing specific roles, denying specific roles, and checking for multiple required permissions. This provides a flexible way to secure entire sections of your application. ```php // Allow roles `administrator` and `editor` access the routes under group. Route::group([ 'middleware' => 'admin.permission:allow,administrator,editor', ], function ($router) { $router->resource('users', UserController::class); ... }); // Deny roles `developer` and `operator` access the routes under group. Route::group([ 'middleware' => 'admin.permission:deny,developer,operator', ], function ($router) { $router->resource('users', UserController::class); ... }); // User has permission `edit-post`、`create-post` and `delete-post` can access routes under group. Route::group([ 'middleware' => 'admin.permission:check,edit-post,create-post,delete-post', ], function ($router) { $router->resource('posts', PostController::class); ... }); ``` -------------------------------- ### Load Laravel Admin Config in Service Provider Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/extension-config.md Modify the `AppServiceProvider.php` file to call `Config::load()` within the `boot` method. This ensures that configuration data stored in the database is loaded when the Laravel application starts. ```PHP perPages([10, 20, 30, 40, 50]); ``` -------------------------------- ### Add Columns to Laravel Admin Grid Source: https://github.com/z-song/laravel-admin/blob/master/docs/zh/model-grid.md PHP examples showing different ways to add columns to a Laravel Admin grid: directly by field name, using the `column()` method, and adding multiple columns at once using `columns()`. ```php // Add column directly by field name `username` $grid->username('Username'); // Same effect as above $grid->column('username', 'Username'); // Add multiple columns $grid->columns('email', 'username' ...); ``` -------------------------------- ### Define Scheduled Tasks in Laravel's Console Kernel Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/extension-scheduling.md This PHP code demonstrates how to add scheduled tasks within the `schedule` method of Laravel's `app/Console/Kernel.php`. It includes examples for running a command every ten minutes and another daily at 2:00 AM, which will then be visible in the web interface. ```php class Kernel extends ConsoleKernel { protected function schedule(Schedule $schedule) { $schedule->command('inspire')->everyTenMinutes(); $schedule->command('route:list')->dailyAt('02:00'); } } ``` -------------------------------- ### Add a Single Row of Content in Laravel-Admin Layout Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/content-layout.md This example illustrates how to add a simple, full-width row of content to the page layout using the `$content->row()` method. It highlights the basic usage of the Bootstrap grid system where each line has a length of 12 units. ```php $content->row('hello') ``` -------------------------------- ### Generate Table Components with Array and Associative Array Data in Laravel Admin Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/widgets.md Demonstrates how to use `Encore\Admin\Widgets\Table` to display tabular data. It shows two examples: one with a standard array of rows and headers, and another with an associative array for key-value pairs, then renders both tables. ```php use Encore\Admin\Widgets\Table; // table 1 $headers = ['Id', 'Email', 'Name', 'Company']; $rows = [ [1, 'labore21@yahoo.com', 'Ms. Clotilde Gibson', 'Goodwin-Watsica'], [2, 'omnis.in@hotmail.com', 'Allie Kuhic', 'Murphy, Koepp and Morar'], [3, 'quia65@hotmail.com', 'Prof. Drew Heller', 'Kihn LLC'], [4, 'xet@yahoo.com', 'William Koss', 'Becker-Raynor'], [5, 'ipsa.aut@gmail.com', 'Ms. Antonietta Kozey Jr.'], ]; $table = new Table($headers, $rows); echo $table->render(); // table 2 $headers = ['Keys', 'Values']; $rows = [ 'name' => 'Joe', 'age' => 25, 'gender' => 'Male', 'birth' => '1989-12-05', ]; $table = new Table($headers, $rows); echo $table->render(); ``` -------------------------------- ### Customize Model Grid Column Display with Callback Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/model-grid-column.md Demonstrates how to use the `display()` method on a `model-grid` column to apply a custom callback function for rendering the column's value. The example shows wrapping the title in a blue-colored span. ```php $grid->column('title')->display(function ($title) { return "$title"; }); ``` -------------------------------- ### Check Permission in Controller Action Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/permission.md This example demonstrates how to restrict access to a controller action. By calling `Permission::check('create-post')`, only users with the 'create-post' permission assigned to their roles can execute this action. This ensures fine-grained control over backend functionalities. ```php use Encore\Admin\Auth\Permission; class PostController extends Controller { public function create() { // check permission, only the roles with permission `create-post` can visit this action Permission::check('create-post'); } } ``` -------------------------------- ### Laravel Admin: Datetime Range Selector Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/model-form-fields.md Demonstrates how to create a datetime range selector using two separate fields for start and end datetimes. ```php $form->datetimeRange($startDateTime, $endDateTime, 'DateTime Range'); ``` -------------------------------- ### SQL Schema for Movies Table Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/model-grid.md Defines the database schema for a `movies` table, including fields like `id`, `title`, `director`, `describe`, `rate`, `released`, and timestamps. This table serves as the data source for the Laravel Admin grid examples. ```SQL CREATE TABLE `movies` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `title` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `director` int(10) unsigned NOT NULL, `describe` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `rate` tinyint unsigned NOT NULL, `released` enum(0, 1), `release_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; ``` -------------------------------- ### Applying String Helper Methods to Laravel Admin Grid Columns Source: https://github.com/z-song/laravel-admin/blob/master/docs/zh/model-grid-column.md Demonstrates how to chain `Illuminate\Support\Str` methods directly onto grid columns that output string values. This allows for convenient string manipulation like limiting length, capitalizing, or getting substrings. ```PHP $grid->title(); ``` ```PHP $grid->title()->limit(30); ``` ```PHP $grid->title()->limit(30)->ucfirst(); $grid->title()->limit(30)->ucfirst()->substr(1, 10); ``` -------------------------------- ### Laravel Admin Route Permission Middleware Configuration Source: https://github.com/z-song/laravel-admin/blob/master/docs/zh/permission.md Examples of configuring route groups with `admin.permission` middleware to control access. Demonstrates allowing specific roles, denying specific roles, and requiring multiple permissions for route access. ```php // 允许administrator、editor两个角色访问group里面的路由 Route::group([ 'middleware' => 'admin.permission:allow,administrator,editor', ], function ($router) { $router->resource('users', UserController::class); ... }); // 禁止developer、operator两个角色访问group里面的路由 Route::group([ 'middleware' => 'admin.permission:deny,developer,operator', ], function ($router) { $router->resource('users', UserController::class); ... }); // 有edit-post、create-post、delete-post三个权限的用户可以访问group里面的路由 Route::group([ 'middleware' => 'admin.permission:check,edit-post,create-post,delete-post', ], function ($router) { $router->resource('posts', PostController::class); ... }); ``` -------------------------------- ### Nest Rows and Columns within Laravel-Admin Layout Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/content-layout.md This example illustrates a more intricate nesting pattern, where a column contains multiple rows, and one of those nested rows further contains its own set of columns. This showcases the flexibility of `laravel-admin`'s layout system for building highly customized page structures. ```php $content->row(function (Row $row) { $row->column(4, 'xxx'); $row->column(8, function (Column $column) { $column->row('111'); $column->row('222'); $column->row(function(Row $row) { $row->column(6, '444'); $row->column(6, '555'); }); }); }); ``` -------------------------------- ### Add Multiple Columns within a Laravel-Admin Row Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/content-layout.md These examples demonstrate how to divide a single row into multiple columns using the `$row->column()` method within a closure. It shows how to create both equal-width (4, 4, 4) and unequal-width (4, 8) column distributions, leveraging Bootstrap's 12-column grid system. ```php $content->row(function(Row $row) { $row->column(4, 'foo'); $row->column(4, 'bar'); $row->column(4, 'baz'); }); ``` ```php $content->row(function(Row $row) { $row->column(4, 'foo'); $row->column(8, 'bar'); }); ``` -------------------------------- ### Chain Collection Helper Methods on Laravel Admin Grid Array Column Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/model-grid-column.md Illustrates chaining `Illuminate\Support\Collection` methods like `pluck()` and `map()` on an array column to transform its elements. This example converts an array of names to have their first letter capitalized. ```php $grid->tags()->pluck('name')->map('ucwords'); ``` -------------------------------- ### Modify Laravel Admin Grid Data Source Source: https://github.com/z-song/laravel-admin/blob/master/docs/zh/model-grid.md PHP examples demonstrating how to modify the underlying Eloquent query for the grid's data source using the `model()` method, allowing for `where`, `orderBy`, `take`, and other Eloquent query builder methods. ```php $grid->model()->where('id', '>', 100); $grid->model()->orderBy('id', 'desc'); $grid->model()->take(100); ... ``` -------------------------------- ### Display One-to-One Related Model Data in Laravel Admin Grid Source: https://github.com/z-song/laravel-admin/blob/master/docs/zh/model-grid.md PHP example showing how to display data from a one-to-one related model (`Profile`) within a `User` grid. It demonstrates accessing related fields directly using dot notation (`profile.age`) or chaining methods (`profile()->age()`). ```php Admin::grid(User::class, function (Grid $grid) { $grid->id('ID')->sortable(); $grid->name(); $grid->email(); $grid->column('profile.age'); $grid->column('profile.gender'); //or $grid->profile()->age(); $grid->profile()->gender(); $grid->created_at(); $grid->updated_at(); }); ``` -------------------------------- ### API Documentation for Encore\Admin\Widgets\InfoBox Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/widgets.md Reference for the `Encore\Admin\Widgets\InfoBox` class, detailing its constructor for creating information presentation blocks. ```APIDOC Encore\Admin\Widgets\InfoBox: __construct($title, $icon, $color, $link, $value) $title: The title of the info box. $icon: The icon to display. $color: The background color of the info box. $link: The URL to link to. $value: The main value or text to display. ``` -------------------------------- ### Customize Column Display Output in Laravel Admin Grid Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/model-grid.md Demonstrates how to use the `display()` method with a closure to format column output. Examples include limiting text length, adding HTML labels, creating mailto links, and displaying content for columns not directly in the database. It also highlights accessing other row data within the closure. ```PHP use Illuminate\Support\Str; $grid->text()->display(function($text) { return Str::limit($text, 30, '...'); }); $grid->name()->display(function ($name) { return "$name"; }); $grid->email()->display(function ($email) { return "mailto:$email"; }); // column not in table $grid->column('column_not_in_table')->display(function () { return 'blablabla....'; }); $grid->first_name(); $grid->last_name(); // column not in table $grid->column('full_name')->display(function () { return $this->first_name.' '.$this->last_name; }); ``` -------------------------------- ### API Documentation for Encore\Admin\Widgets\Collapse Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/widgets.md Reference for the `Encore\Admin\Widgets\Collapse` class, detailing its methods for creating collapsible components. ```APIDOC Encore\Admin\Widgets\Collapse: add($title, $content) $title: The title of the collapsed item. $content: The content of the collapsed item. ``` -------------------------------- ### API Documentation for Encore\Admin\Widgets\Table Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/widgets.md Reference for the `Encore\Admin\Widgets\Table` class, detailing its constructor for creating table components. ```APIDOC Encore\Admin\Widgets\Table: __construct($headers, $rows) $headers: An array of column headers for the table. $rows: An array of data rows for the table. Can be a standard indexed array or an associative array for key-value pairs. ``` -------------------------------- ### API Documentation for Encore\Admin\Widgets\Box Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/widgets.md Reference for the `Encore\Admin\Widgets\Box` class, detailing its constructor and methods for creating and customizing box components. ```APIDOC Encore\Admin\Widgets\Box: __construct($title, $content) $title: The title of the box. $content: The content element of the box, can be an implementation of `Illuminate\Contracts\Support\Renderable` or other printable variables. title($title) $title: Sets the title of the Box component. content($content) $content: Sets the content element of the Box component. removable() Sets the Box component as removable. collapsable() Sets the Box component as collapsable. style($style) $style: Sets the style of the Box component. Valid values: `primary`, `info`, `danger`, `warning`, `success`, `default`. solid() Adds a border to the Box component. ``` -------------------------------- ### Generate and Configure a Box Component in Laravel Admin Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/widgets.md Demonstrates how to instantiate and configure an `Encore\Admin\Widgets\Box` component. It shows setting a title and content, making it removable and collapsable, applying a specific style, and adding a solid border before rendering the component. ```php use Encore\Admin\Widgets\Box; $box = new Box('Box Title', 'Box content'); $box->removable(); $box->collapsable(); $box->style('info'); $box->solid(); echo $box; ``` -------------------------------- ### API Documentation for Encore\Admin\Widgets\Tab Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/widgets.md Reference for the `Encore\Admin\Widgets\Tab` class, detailing its methods for creating tab components. ```APIDOC Encore\Admin\Widgets\Tab: add($title, $content) $title: The title of the new tab. $content: The content of the new tab. ``` -------------------------------- ### Apply Between Filter to Model Grid Column (PHP) Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/model-grid-filters.md Filters records where a column's value falls within a specified start and end range. Can be configured for datetime or time fields. Corresponds to SQL: `... WHERE `column` BETWEEN "$start" AND "$end"`. ```php $filter->between('column', $label); ``` ```php $filter->between('column', $label)->datetime(); ``` ```php $filter->between('column', $label)->time(); ``` -------------------------------- ### Disable Query Filter in Laravel Admin Grid Source: https://github.com/z-song/laravel-admin/blob/master/docs/zh/model-grid.md PHP example to disable the query filter on the Laravel Admin grid using `disableFilter()`. ```php $grid->disableFilter(); ``` -------------------------------- ### API Documentation for Encore\Admin\Widgets\Form Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/widgets.md Reference for the `Encore\Admin\Widgets\Form` class, detailing its constructor and methods for building forms. ```APIDOC Encore\Admin\Widgets\Form: __construct($data = []) $data: An optional array whose elements will be filled into the form. action($uri) $uri: Sets the form submission address. method($method) $method: Sets the submit method of the form (default is `POST`). disablePjax() Disables PJAX for form submission. ``` -------------------------------- ### Disable Pagination Bar in Laravel Admin Grid Source: https://github.com/z-song/laravel-admin/blob/master/docs/zh/model-grid.md PHP example to disable the pagination bar on the Laravel Admin grid using `disablePagination()`. ```php $grid->disablePagination(); ``` -------------------------------- ### Generate an InfoBox Component in Laravel Admin Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/widgets.md Demonstrates the instantiation of an `Encore\Admin\Widgets\InfoBox` component. It shows how to pass parameters for title, icon, color, link, and value to create an information presentation block, then renders it. ```php use Encore\Admin\Widgets\InfoBox; $infoBox = new InfoBox('New Users', 'users', 'aqua', '/admin/users', '1024'); echo $infoBox->render(); ``` -------------------------------- ### Disable Create Button in Laravel Admin Grid Source: https://github.com/z-song/laravel-admin/blob/master/docs/zh/model-grid.md PHP example to disable the 'Create' button on the Laravel Admin grid using `disableCreateButton()`. ```php $grid->disableCreateButton(); ``` -------------------------------- ### Disable Export Button in Laravel Admin Grid Source: https://github.com/z-song/laravel-admin/blob/master/docs/zh/model-grid.md PHP example to disable the export data button on the Laravel Admin grid using `disableExport()`. ```php $grid->disableExport(); ``` -------------------------------- ### Publish API Tester Vendor Assets Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/extension-api-tester.md Publishes the necessary vendor assets for the `api-tester` extension. This command makes the package's resources, such as configuration files and views, available in your application. ```shell $ php artisan vendor:publish --tag=api-tester ``` -------------------------------- ### Generate Laravel Admin Grid for Movies Source: https://github.com/z-song/laravel-admin/blob/master/docs/zh/model-grid.md PHP code demonstrating how to initialize an `Encore\Admin\Grid` for the `App\Models\Movie` model. It defines various columns, including `id`, `title`, `director` (with a display callback to show user name), `describe`, `rate`, `released` (with a display callback for 'Yes'/'No'), `release_at`, `created_at`, and `updated_at`. Also includes a filter for `created_at`. ```php use App\Models\Movie; use Encore\Admin\Grid; use Encore\Admin\Facades\Admin; $grid = Admin::grid(Movie::class, function(Grid $grid){ // The first column displays the id field and sets this column as sortable $grid->id('ID')->sortable(); // The second column displays the title field. Since the title field name conflicts with the Grid object's title method, use the Grid's column() method instead $grid->column('title'); // The third column displays the director field. Use the display($callback) method to set the display content of this column to the corresponding username in the users table $grid->director()->display(function($userId) { return User::find($userId)->name; }); // The fourth column displays the describe field $grid->describe(); // The fifth column displays the rate field $grid->rate(); // The sixth column displays the released field, formatted using the display($callback) method $grid->released('Released?')->display(function ($released) { return $released ? 'Yes' : 'No'; }); // The following are three time field columns $grid->release_at(); $grid->created_at(); $grid->updated_at(); // The filter($callback) method is used to set up a simple search box for the table $grid->filter(function ($filter) { // Set up a range query for the created_at field $filter->between('created_at', 'Created Time')->datetime(); }); }); ``` -------------------------------- ### Laravel Admin: Date Range Selector Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/model-form-fields.md Illustrates how to create a date range selector using two separate fields for start and end dates. ```php $form->dateRange($startDate, $endDate, 'Date Range'); ``` -------------------------------- ### Laravel Admin: Time Range Selector Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/model-form-fields.md Shows how to create a time range selector using two separate fields for start and end times. ```php $form->timeRange($startTime, $endTime, 'Time Range'); ``` -------------------------------- ### Disable Row Selector Checkbox in Laravel Admin Grid Source: https://github.com/z-song/laravel-admin/blob/master/docs/zh/model-grid.md PHP example to disable the row selection checkboxes on the Laravel Admin grid using `disableRowSelector()`. ```php $grid->disableRowSelector(); ``` -------------------------------- ### Build a Form Component with Various Input Types in Laravel Admin Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/widgets.md Shows how to quickly build a form using `Encore\Admin\Widgets\Form`. It demonstrates setting the form action and adding various input fields such as email, password, text, URL, color, map coordinates, date, JSON, and date range, then rendering the form. ```php $form = new Form(); $form->action('example'); $form->email('email')->default('qwe@aweq.com'); $form->password('password'); $form->text('name'); $form->url('url'); $form->color('color'); $form->map('lat', 'lng'); $form->date('date'); $form->json('val'); $form->dateRange('created_at', 'updated_at'); echo $form->render(); ``` -------------------------------- ### Display Array Column in Laravel Admin Grid Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/model-grid-column.md Shows how to display an array-type column, typically from a one-to-many relationship, in a Laravel Admin grid. The example output demonstrates the structure of such an array. ```php $grid->tags(); ``` -------------------------------- ### Disable Row Actions Column in Laravel Admin Grid Source: https://github.com/z-song/laravel-admin/blob/master/docs/zh/model-grid.md PHP example to disable the actions column (edit, delete, view) for each row on the Laravel Admin grid using `disableActions()`. ```php $grid->disableActions(); ``` -------------------------------- ### Configure Public Disk URL for Media Preview in config/filesystem.php Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/extension-media-manager.md This PHP snippet demonstrates how to configure the 'public' disk in `config/filesystem.php` to include an access URL. Setting the 'url' property is crucial for enabling image previews when using the media manager. ```PHP 'disks' => [ 'public' => [ 'driver' => 'local', 'root' => storage_path('app/public'), 'url' => env('APP_URL').'/storage', // set url 'visibility' => 'public', ], ... ] ``` -------------------------------- ### Use Custom CKEditor Field in Laravel Admin Form Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/model-form-field-management.md Once the custom CKEditor field is registered, this example shows how to easily add it to a Laravel Admin form using `$form->ckeditor('content');`. ```PHP $form->ckeditor('content'); ``` -------------------------------- ### Laravel Admin: Checkbox Group Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/model-form-fields.md Shows how to create a group of checkboxes with predefined options. Checkbox values can be stored similarly to multiple select fields. Includes an example of stacked layout. ```php $form->checkbox($column[, $label])->options([1 => 'foo', 2 => 'bar', 'val' => 'Option name']); ``` ```php $form->checkbox($column[, $label])->options([1 => 'foo', 2 => 'bar', 'val' => 'Option name'])->stacked(); ``` -------------------------------- ### Create a Tab Component with Multiple Panels in Laravel Admin Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/widgets.md Illustrates how to use `Encore\Admin\Widgets\Tab` to create a tabbed interface. It shows adding multiple tabs, each with a title and content, which can include other widgets or plain text, and then rendering the component. ```php use Encore\Admin\Widgets\Tab; $tab = new Tab(); $tab->add('Pie', $pie); $tab->add('Table', new Table()); $tab->add('Text', 'blablablabla....'); echo $tab->render(); ``` -------------------------------- ### Define Page Content with Laravel-Admin Content Class Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/content-layout.md This snippet demonstrates how to use the `Admin::content` method within a controller's `index()` method to define the structure and content of a page. It shows how to set optional elements like headers, descriptions, and breadcrumbs, and how to fill the main page body with a simple string or any renderable object. ```php public function index() { return Admin::content(function (Content $content) { // optional $content->header('page header'); // optional $content->description('page description'); // add breadcrumb since v1.5.7 $content->breadcrumb( ['text' => 'Dashboard', 'url' => '/admin'], ['text' => 'User management', 'url' => '/admin/users'], ['text' => 'Edit user'] ); // Fill the page body part, you can put any renderable objects here $content->body('hello world'); }); } ``` -------------------------------- ### Retrieve Configuration Value from Database Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/extension-config.md After adding configuration entries through the admin panel, use the global `config($key)` helper function in your PHP code to easily retrieve the stored value associated with a specific key. ```PHP config($key) ``` -------------------------------- ### PHP Customizing Model-Tree Branch Display Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/model-tree.md Explains how to customize the display of individual branches in the `model-tree` using the `branch` method. This allows modifying the HTML representation of each node, for example, by adding an image or custom text based on the branch data. ```php Category::tree(function ($tree) { $tree->branch(function ($branch) { $src = config('admin.upload.host') . '/' . $branch['logo'] ; $logo = ""; return "{$branch['id']} - {$branch['title']} $logo"; }); }) ``` -------------------------------- ### Modify Grid Source Data in Laravel Admin Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/model-grid.md Explains how to manipulate the underlying query for the grid's data using the `model()` method. Examples include applying `where` clauses, `orderBy` for sorting, and `take` for limiting results. ```PHP $grid->model()->where('id', '>', 100); $grid->model()->orderBy('id', 'desc'); $grid->model()->take(100); ``` -------------------------------- ### Create a Collapse Component with Multiple Items in Laravel Admin Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/widgets.md Illustrates how to use `Encore\Admin\Widgets\Collapse` to create a collapsible section. It demonstrates adding multiple items, each with a title and content, including another widget like a Table, and then rendering the component. ```php use Encore\Admin\Widgets\Collapse; $collapse = new Collapse(); $collapse->add('Bar', 'xxxxx'); $collapse->add('Orders', new Table()); echo $collapse->render(); ``` -------------------------------- ### Import API Tester Menus and Permissions Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/extension-api-tester.md Imports the required menu entries and permissions for the `api-tester` into the Laravel Admin panel. This step provides the entry link to the API tester interface within your admin dashboard. ```shell $ php artisan admin:import api-tester ``` -------------------------------- ### Define Laravel Admin Column Extension Class Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/model-grid-column.md Illustrates how to create a more complex column displayer by defining an extension class, `Popover`, that extends `Encore\Admin\Grid\Displayers\AbstractDisplayer`. This class encapsulates the display logic, including JavaScript initialization and HTML rendering for a Bootstrap popover button. ```php value}" > Popover EOT; } } ``` -------------------------------- ### Use Custom PHP Editor Field in Laravel Admin Form Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/model-form-field-management.md Once the custom PHP editor field is registered, this example shows how to easily add it to a Laravel Admin model form using `$form->php('code');`. ```PHP $form->php('code'); ``` -------------------------------- ### Import Laravel Admin Config Menus and Permissions Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/extension-config.md Run this Artisan command to automatically import the default menu items and permissions required for the Laravel Admin configuration module. This step is optional as menus can also be added manually. ```Shell $ php artisan admin:import config ``` -------------------------------- ### Implement Backend API for Batch Post Release/Unrelease Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/model-grid-custom-tools.md This PHP method, intended for a Laravel controller (e.g., `PostController`), handles the backend logic for batch post operations. It receives an array of `ids` and an `action` from the front-end, iterates through the selected posts, updates their `released` status, and saves the changes to the database. ```PHP class PostController extends Controller { ... public function release(Request $request) { foreach (Post::find($request->get('ids')) as $post) { $post->released = $request->get('action'); $post->save(); } } ... } ``` -------------------------------- ### Configure Media Manager Disk in config/admin.php Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/extension-media-manager.md This PHP snippet shows how to configure the 'media-manager' extension in `config/admin.php` to specify the disk it should manage. The 'disk' property should point to a disk defined in `config/filesystem.php`. ```PHP 'extensions' => [ 'media-manager' => [ 'disk' => 'public' // Points to the disk set in config/filesystem.php ], ], ``` -------------------------------- ### Set Pagination Row Count for Laravel Admin Grid Source: https://github.com/z-song/laravel-admin/blob/master/docs/zh/model-grid.md PHP example to set the number of items displayed per page in the Laravel Admin grid using the `paginate()` method. Defaults to 20 items per page. ```php // Defaults to 20 items per page $grid->paginate(15); ``` -------------------------------- ### Configure Eloquent Model for Data Grid Source: https://github.com/z-song/laravel-admin/blob/master/docs/zh/model-grid-data.md Demonstrates how to apply default query conditions and initial sorting to an Eloquent model when used as a data source for a grid in Laravel Admin. It shows basic `where` and `orderBy` clauses to filter and order data. ```php // 添加默认查询条件 $grid->model()->where('id', '>', 100); // 设置初始排序条件 $grid->model()->orderBy('id', 'desc'); ``` -------------------------------- ### Setting Laravel Admin Upload Disk for Cloud Storage (Qiniu) Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/model-form-upload.md Shows how to modify the `config/admin.php` file to select the 'qiniu' disk for cloud storage uploads. This configuration directs Laravel Admin to use the specified cloud service for storing images and files, utilizing the previously defined Qiniu disk. ```php 'upload' => [ 'disk' => 'qiniu', 'directory' => [ 'image' => 'image', 'file' => 'file' ] ], ``` -------------------------------- ### Configuring Local Storage Disk for Laravel Admin Uploads Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/model-form-upload.md Shows how to add a new local disk configuration named 'admin' in `config/filesystems.php`. This disk points to `public_path('uploads')` and is configured for public visibility, serving as the local storage destination for files and images uploaded via Laravel Admin. ```php 'disks' => [ ... , 'admin' => [ 'driver' => 'local', 'root' => public_path('uploads'), 'visibility' => 'public', 'url' => env('APP_URL').'/uploads', ], ], ``` -------------------------------- ### Illuminate Authenticatable Interface Definition in PHP Source: https://github.com/z-song/laravel-admin/blob/master/docs/en/custom-authentication.md This PHP code block shows the definition of the `Illuminate\Contracts\Auth\Authenticatable` interface. Any user object used with Laravel's authentication system must implement this interface, providing methods to get the user's identifier, password, and remember token details. ```php ['text' => 'YES'], 'off' => ['text' => 'NO'], ]; $grid->column('switch_group')->switchGroup([ 'hot' => 'Hot', 'new' => 'New', 'recommend' => 'Recommend' ], $states); ``` -------------------------------- ### Handle Batch Post Release/Unpublish in Laravel Controller (PHP) Source: https://github.com/z-song/laravel-admin/blob/master/docs/zh/model-grid-custom-tools.md This PHP controller method, `release`, handles the backend logic for batch post operations. It receives an array of post IDs and an 'action' parameter (1 for publish, 0 for unpublish) from the frontend. It then iterates through the selected posts, updates their 'released' status, and saves the changes. ```PHP class PostController extends Controller { ... public function release(Request $request) { foreach (Post::find($request->get('ids')) as $post) { $post->released = $request->get('action'); $post->save(); } } ... } ```