### Install laravel-admin Source: https://laravel-admin.org/docs/en Run the Artisan command to complete the laravel-admin installation. This will set up the necessary database tables and default configurations. ```bash php artisan admin:install ``` -------------------------------- ### Install Laravel Admin Configuration Extension Source: https://laravel-admin.org/docs/en/extension-config Install the configuration extension using Composer and run the database migration. ```bash $ composer require laravel-admin-ext/config $ php artisan migrate ``` -------------------------------- ### Install Minify Dependency Source: https://laravel-admin.org/docs/en/frontend Install the `matthiasmullie/minify` package using Composer to enable asset minification. ```bash composer require matthiasmullie/minify --dev ``` -------------------------------- ### Install Media Manager Extension Source: https://laravel-admin.org/docs/en/extension-media-manager Install the Media Manager extension using Composer and register it with the Laravel Admin panel. ```bash $ composer require laravel-admin-ext/media-manager -vvv $ php artisan admin:import media-manager ``` -------------------------------- ### Publish Assets and Configuration Source: https://laravel-admin.org/docs/en After installing the package, publish its assets and configuration files using the Artisan command. ```bash php artisan vendor:publish --provider="Encore\Admin\AdminServiceProvider" ``` -------------------------------- ### Local Extension Installation with Composer Source: https://laravel-admin.org/docs/en/extension-development Configure composer.json to point to a local extension directory for development. This allows for iterative testing and debugging. ```json { "repositories": [ { "type": "path", "url": "app/Admin/extensions/laravel-admin-ext/phpinfo" } ] } ``` -------------------------------- ### Publishing Extension Static Assets Source: https://laravel-admin.org/docs/en/extension-development Use this command to publish any static assets (like CSS or JS) required by your extension after installation. ```bash php artisan vendor:publish --provider=Encore\PHPInfo\PHPInfoServiceProvider ``` -------------------------------- ### Install laravel-admin Composer Package Source: https://laravel-admin.org/docs/en Use Composer to install the laravel-admin package. Ensure you have PHP 7+ and Laravel 5.5+. ```bash composer require encore/laravel-admin ``` -------------------------------- ### Get User Permissions Source: https://laravel-admin.org/docs/en/permission Fetch a list of all permissions granted to the current user. ```php Admin::user()->permissions; ``` -------------------------------- ### Define Extension Route Source: https://laravel-admin.org/docs/en/extension-development Add a route to `routes/web.php` to handle requests for your extension's functionality. This example maps the 'phpinfo' URL to a controller method. ```php column(1/2, function ($form) { // Add a form item to this column $form->text('title', __('Title'))->rules('min:10'); $form->textarea('desc', __('Desc'))->required(); $form->select('uploader_id', __('Uploader')) ->options(User::all()->pluck('name', 'id')) ->rules('required'); ; $form->file('path', __('Path'))->required(); }); // The second column occupies 1/2 of the page width to the right $form->column(1/2, function ($form) { $form->number('view_count', __('View count'))->default(0); $form->number('download_count', __('Download count'))->default(0); $form->number('rate', __('Rate'))->default(0); $form->radio('privilege', __('Privilege')) ->options(Document::$privileges) ->stacked() ->default(1); $form->datetimeRange('created_at', 'updated_at'); }); return $form; ``` -------------------------------- ### Include Extension Static Resources Source: https://laravel-admin.org/docs/en/extension-development Register JavaScript and CSS files for the extension to be included when Laravel Admin starts. Ensure the files are correctly placed in the public directory after publishing. ```php use use Encore\Admin\Admin; ... Admin::booting(function () { Admin::js('vendor/laravel-admin-ext/phpinfo/foo.js'); Admin::css('vendor/laravel-admin-ext/phpinfo/bar.css'); }); ``` -------------------------------- ### Get Configured Value Source: https://laravel-admin.org/docs/en/extension-config Retrieve a configured value from the database using the `config($key)` helper function after adding it in the admin panel. ```php config($key) ``` -------------------------------- ### Get User Roles Source: https://laravel-admin.org/docs/en/permission Retrieve a collection of roles assigned to the current user. ```php Admin::user()->roles; ``` -------------------------------- ### Conditional Form Fields with Checkboxes Source: https://laravel-admin.org/docs/en/model-form-linkage Implement form linkage for multi-select components like checkboxes using the `when()` method. This example shows how to display fields based on specific selected values or combinations of values. ```php $form->checkbox('nationality','Nationality') ->options([ 1 =>'China', 2 =>'foreign', ])->when([1, 2], function (Form $form) { $form->text('name','Name'); $form->text('idcard','ID card'); })->when('has', 2, function (Form $form) { $form->text('name','Name'); $form->text('passport','Passport'); }); ``` -------------------------------- ### Get Current User ID Source: https://laravel-admin.org/docs/en/permission Access the unique identifier of the currently logged-in user. ```php Admin::user()->id; ``` -------------------------------- ### Get Current User Object Source: https://laravel-admin.org/docs/en/permission Retrieve the current logged-in user object for accessing user-specific information and methods. ```php Admin::user(); ``` -------------------------------- ### Conditional Form Fields with Radio Buttons Source: https://laravel-admin.org/docs/en/model-form-linkage Use the `when()` method on radio components to conditionally display other form fields based on the selected option. This example shows how selecting 'Home country' displays 'Name' and 'ID card', while 'foreign' displays 'Name' and 'Passport'. ```php $form->radio('nationality','Nationality') ->options([ 1 =>'Home country', 2 =>'foreign', ])->when(1, function (Form $form) { $form->text('name','Name'); $form->text('idcard','ID card'); })->when(2, function (Form $form) { $form->text('name','Name'); $form->text('passport','Passport'); }); ``` -------------------------------- ### Import Configuration Menus and Permissions Source: https://laravel-admin.org/docs/en/extension-config Import the necessary menus and permissions for the configuration extension using the Artisan command. ```bash $ php artisan admin:import config ``` -------------------------------- ### Introduce CSS and JavaScript Files Source: https://laravel-admin.org/docs/en/frontend Use these methods in `app/Admin/bootstrap.php` to include local or external CSS and JavaScript files. Paths are relative to the public directory. ```php Admin::css('/your/css/path/style.css'); Admin::js('/your/javascript/path/js.js'); ``` ```php Admin::js('https://cdn.bootcss.com/vue/2.6.10/vue.min.js'); ``` -------------------------------- ### Initializing Git Repository for Extension Source: https://laravel-admin.org/docs/en/extension-development Initialize a new Git repository and set up the remote origin for your extension's code hosted on GitHub. ```bash git init git remote add origin https://github.com//.git git add . git commit -am "Initial commit." git push origin master ``` -------------------------------- ### Configure Filesystem Disk URL Source: https://laravel-admin.org/docs/en/extension-media-manager Ensure the 'url' is set for the chosen disk in `config/filesystem.php` to enable image previews. ```php 'disks' => [ 'public' => [ 'driver' => 'local', 'root' => storage_path('app/public'), 'url' => env('APP_URL').'/storage', // set url 'visibility' => 'public', ], ... ] ``` -------------------------------- ### Register Configuration Loading in AppServiceProvider Source: https://laravel-admin.org/docs/en/extension-config Register the `Config::load()` method in the `boot` method of `app/Providers/AppServiceProvider.php` to enable configuration loading. ```php [ 'media-manager' => [ 'disk' => 'public' // Points to the disk set in config/filesystem.php ], ], ``` -------------------------------- ### Enable Asset Minification Configuration Source: https://laravel-admin.org/docs/en/frontend Add this configuration option to `config/admin.php` to enable the asset minification feature. ```php 'minify_assets' => true, ``` -------------------------------- ### Define Extension Properties in PHPInfo.php Source: https://laravel-admin.org/docs/en/extension-development Set the extension's name, view paths, assets, and menu configuration. Remove unnecessary attributes as needed. ```php 'Phpinfo', 'path' => 'phpinfo', 'icon' => 'fa-gears', ]; } ``` ```php 'PHP info', 'path' => 'phpinfo', 'icon' => 'fa-exclamation', ]; } ``` -------------------------------- ### Tagging a Release for Extension Source: https://laravel-admin.org/docs/en/extension-development Create a Git tag for a specific version of your extension and push it to the remote repository. This is crucial for version management and Packagist. ```bash git tag 0.0.1 && git push --tags ``` -------------------------------- ### Load Extension Views in ServiceProvider Source: https://laravel-admin.org/docs/en/extension-development Register extension views by loading them from the specified path with a given namespace. This allows using `view('phpinfo::index')`. ```php if ($views = $extension->views()) { $this->loadViewsFrom($views, 'phpinfo'); } ``` -------------------------------- ### Minify CSS and JavaScript Assets Source: https://laravel-admin.org/docs/en/frontend Run this Artisan command to compress local CSS and JS files, speeding up page load times. It generates minified files and a manifest. ```bash $ php artisan admin:minify ``` -------------------------------- ### Create and Configure a Box Widget Source: https://laravel-admin.org/docs/en/widgets Use the Box widget to generate box components with customizable titles, content, and appearance. It supports removable and collapsable features, along with different style options. ```php use Encore\Admin\Widgets\Box; $box = new Box('Box Title', 'Box content'); $box->removable(); $box->collapsable(); $box->style('info'); $box->solid(); echo $box; ``` -------------------------------- ### Define Route for Extension Data Source: https://laravel-admin.org/docs/en/extension-development Create a route to display PHP configuration data by calling the extension's `toCollection` method and rendering it in a view. The route path can be configured via `PHPInfo::config('path', 'phpinfo')`. ```php toCollection(); return $content ->header('PHP\'s configuration') ->description(' ') ->body(view('phpinfo::phpinfo', compact('info'))); }); ``` -------------------------------- ### Create an InfoBox Widget Source: https://laravel-admin.org/docs/en/widgets Generate an information presentation block using the InfoBox widget. It displays a title, icon, color, link, and a value, suitable for dashboards and summary views. ```php use Encore\Admin\Widgets\InfoBox; $infoBox = new InfoBox('New Users', 'users', 'aqua', '/admin/users', '1024'); echo $infoBox->render(); ``` -------------------------------- ### Publish Extension Assets in ServiceProvider Source: https://laravel-admin.org/docs/en/extension-development Configure the publishing of static assets to the public directory when the application is running in the console. This is done using `php artisan vendor:publish`. ```php if ($this->app->runningInConsole() && $assets = $extension->assets()) { $this->publishes( [$assets => public_path('vendor/laravel-admin-ext/phpinfo')], 'phpinfo' ); } ``` -------------------------------- ### Generate Extension Skeleton Source: https://laravel-admin.org/docs/en/extension-development Use the `admin:extend` Artisan command to generate the basic file structure for a new Laravel-Admin extension. Specify the package name and namespace. ```bash Php artisan admin:extend laravel-admin-ext/phpinfo --namespace=Encore\PHPInfo ``` -------------------------------- ### Create a Collapse Widget Source: https://laravel-admin.org/docs/en/widgets The Collapse widget generates folding components, allowing content to be shown or hidden. Use the `add` method to include items with titles and associated content. ```php use Encore\Admin\Widgets\Collapse; $collapse = new Collapse(); $collapse->add('Bar', 'xxxxx'); $collapse->add('Orders', new Table()); echo $collapse->render(); ``` -------------------------------- ### Clear Minified Assets Source: https://laravel-admin.org/docs/en/frontend Execute this command to remove previously generated minified asset files and the manifest, reverting to the pre-compression state. ```bash $ php artisan admin:minify --clear ``` -------------------------------- ### Radio Component Operators for Linkage Source: https://laravel-admin.org/docs/en/model-form-linkage Demonstrates the use of various operators (`>`, `>=`, `in`, `notIn`) with the `when()` method for radio components to define more complex conditional display logic. ```php $form->radio('check') ->when('>', 1, function () { })->when('>=', 2, function () { })->when('in', [5, 6], function () { })->when('notIn', [7, 8], function () { }); ``` -------------------------------- ### Create a Tab Component Widget Source: https://laravel-admin.org/docs/en/widgets The Tab widget generates tab components, allowing you to organize content into different sections. Use the `add` method to define tabs with titles and their corresponding content. ```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(); ``` -------------------------------- ### Check Permissions for Route Access Source: https://laravel-admin.org/docs/en/permission Utilize the `admin.permission` middleware to ensure users possess all specified permissions before granting access to a route group. ```php // 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); ... }); ``` -------------------------------- ### Build a Form Widget Source: https://laravel-admin.org/docs/en/widgets Quickly build form elements using the Form widget. It supports various input types like email, password, text, URL, color, map, date, JSON, and date ranges. You can also set the form action and method. ```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(); ``` -------------------------------- ### Set Website Favicon Source: https://laravel-admin.org/docs/en/frontend Add this code to `app/Admin/bootstrap.php` to set a custom favicon for the admin panel. ```php Use Encore\Admin\Admin; Admin::favicon('/your/favicon/path'); ``` -------------------------------- ### Check if User is in Any of Specified Roles Source: https://laravel-admin.org/docs/en/permission Verify if the current user belongs to at least one of the roles in the provided list. ```php Admin::user()->inRoles(['editor', 'developer']); ``` -------------------------------- ### Insert CSS Style Source: https://laravel-admin.org/docs/en/frontend Use `Admin::style()` to inject CSS code directly into the current page. This can be used for quick styling adjustments. ```php Use Encore\Admin\Admin; Admin::style('.form-control {margin-top: 10px;}'); ``` -------------------------------- ### Generate a Table Widget Source: https://laravel-admin.org/docs/en/widgets Use the Table widget to generate HTML tables. It can be configured with custom headers and rows of data. Supports different data structures for rows. ```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(); ``` -------------------------------- ### Check if User Does Not Have a Specific Permission Source: https://laravel-admin.org/docs/en/permission Verify that the current user lacks a specified permission. ```php Admin::user()->cannot('delete-post'); ``` -------------------------------- ### Insert HTML Code Source: https://laravel-admin.org/docs/en/frontend Use `Admin::html()` to insert raw HTML code into the current page. This is helpful for adding hidden elements or custom templates. ```php Use Encore\Admin\Admin; Admin::html(''); ``` -------------------------------- ### Allow Specific Roles Access to Routes Source: https://laravel-admin.org/docs/en/permission Use the `admin.permission` middleware to grant access to a route group only for specified roles. ```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); ... }); ``` -------------------------------- ### Control Grid Actions Based on Permissions Source: https://laravel-admin.org/docs/en/permission Conditionally disable actions like delete buttons or show/hide columns in a grid based on user permissions. This enhances UI security by hiding sensitive operations from unauthorized users. ```php $grid->actions(function ($actions) { // The roles with this permission will not able to see the delete button in actions column. if (!Admin::user()->can('delete-image')) { $actions->disableDelete(); } }); // Only roles with permission `view-title-column` can view this column in grid if (Admin::user()->can('view-title-column')) { $grid->column('title'); } ``` -------------------------------- ### list Component for One-Dimensional Arrays Source: https://laravel-admin.org/docs/en/model-form-json-fields Use the list component to manage one-dimensional arrays stored in JSON format. It supports setting maximum and minimum element counts and verification rules. ```php $form->list('column_name'); ``` ```php // Set verification rules $form->list('column_name')->rules('required|min:5'); ``` ```php // Set the maximum and minimum number of elements $form->list('column_name')->max(10)->min(5); ``` -------------------------------- ### Check if User is a Specific Role Source: https://laravel-admin.org/docs/en/permission Verify if the current user is assigned a particular role. ```php Admin::user()->isRole('developer'); ``` -------------------------------- ### Deny Specific Roles Access to Routes Source: https://laravel-admin.org/docs/en/permission Employ the `admin.permission` middleware to restrict access to a route group for designated roles. ```php // 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); ... }); ``` -------------------------------- ### Insert JS Script Code Source: https://laravel-admin.org/docs/en/frontend Use `Admin::script()` to inject JavaScript code into the current page. This is useful for form interactions or dynamic effects. ```php Use Encore\Admin\Admin; Admin::script('console.log("hello world");'); ``` -------------------------------- ### Check if User Has a Specific Permission Source: https://laravel-admin.org/docs/en/permission Determine if the current user possesses a given permission. ```php Admin::user()->can('create-post'); ``` -------------------------------- ### keyValue Component for JSON Objects Source: https://laravel-admin.org/docs/en/model-form-json-fields Use the keyValue component to process fields storing JSON in a 'field:value' format. Verification rules can be applied. ```php $form->keyValue('column_name'); ``` ```php // Set verification rules $form->keyValue('column_name')->rules('required|min:5'); ``` -------------------------------- ### Check Permission in Controller Action Source: https://laravel-admin.org/docs/en/permission Use `Permission::check()` to ensure only users with the specified permission can access a controller action. This is useful for granular control over specific 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'); } } ``` -------------------------------- ### Check if User is Super Administrator Source: https://laravel-admin.org/docs/en/permission Determine if the current user has super administrator privileges. ```php Admin::user()->isAdministrator(); ``` -------------------------------- ### table Component for Two-Dimensional Arrays Source: https://laravel-admin.org/docs/en/model-form-json-fields The table component handles two-dimensional arrays in JSON format, similar to the hasMany component but for a single field. Accessor and modifier methods are required in the model. ```php $form->table('column_name', function ($table) { $table->text('key'); $table->text('value'); $table->text('desc'); }); ``` ```php public function getColumnNameAttribute($value) { return array_values(json_decode($value, true) ?: []); } ``` ```php public function setColumnNameAttribute($value) { $this->attributes['column_name'] = json_encode(array_values($value)); } ``` -------------------------------- ### embeds Component for Fixed Key-Value Objects Source: https://laravel-admin.org/docs/en/model-form-json-fields The embeds component is suitable for JSON fields with fixed keys, allowing nested form elements. A custom title can also be provided. ```php $form->embeds('column_name', function ($form) { $form->text('key1')->rules('required'); $form->email('key2')->rules('required'); $form->datetime('key3'); $form->dateRange('key4','key5','Range')->rules('required'); }); ``` ```php // Custom title $form->embeds('column_name','Field title', function ($form) { ... }); ``` -------------------------------- ### Set JSON Cast in Model Source: https://laravel-admin.org/docs/en/model-form-json-fields Before using JSON processing components, ensure the field's cast is set to 'json' in your Eloquent model. ```php class Foo extends Model { protected $casts = [ 'column_name' =>'json', ]; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.