In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "how to use the Laravel admin background management plug-in", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to use the Laravel admin background management plug-in!
Create a Laravel project
Laravel-admin is a background management development framework based on laravel, which can help you to develop a fully functional management background with little time and code. In addition, as a third-party package, it can be developed in parallel with other projects in the framework to truly separate the front and background development.
According to the official documentation, it's easy to create a Laravel project:
/ / download the Laravel installer using Composer
Composer global require "laravel/installer"
/ / create a web project
Laravel new web
Specific configuration database, etc.
Install laravel-admin
Laravel-admin is a tool that can quickly help you build background management. It provides functions such as page components and form elements, which can help you achieve fully functional background management functions with very little code.
Note: the current version (1.5) requires the installation of PHP 7 + and Laravel 5.5
Take a look at the features of laravel-admin:
Built-in user and permissions system
Model-grid supports rapid construction of data tables
Model-form supports rapid construction of data forms
Model-tree supports rapid construction of tree data
Built-in 40 + form element components and support for extension components
Multiple model relationships that support Laravel
Mysql, mongodb, pgsql and other multi-database support
Support the introduction of third-party front-end libraries
Web implementation of Database and artisan Command Line tool
Support for custom charts
Several commonly used web components
Support local and oss file upload
With these functions, it becomes relatively easy to develop a background management system.
Install the plug-in:
Composer require encore/laravel-admin "1.5.*"
/ / publish resources:
Php artisan vendor:publish-provider= "Encore\ Admin\ AdminServiceProvider"
/ / install
Php artisan admin:install
With three simple commands, you can configure a simple background management system. The account number and password are all admin.
The code is mainly concentrated in\ APP\ Admin
The default system provides a Dashboard interface:
Namespace App\ Admin\ Controllers
Use App\ Http\ Controllers\ Controller
Use Encore\ Admin\ Facades\ Admin
Use Encore\ Admin\ Layout\ Column
Use Encore\ Admin\ Layout\ Content
Use Encore\ Admin\ Layout\ Row
Class HomeController extends Controller
{
Public function index ()
{
Return Admin::content (function (Content $content) {
$content- > header ('Test Dashboard')
$content- > description ('Description...')
$content- > row (Dashboard::title ())
$content- > row (function (Row $row) {
$row- > column (4, function (Column $column) {
$column- > append (Dashboard::environment ())
})
$row- > column (4, function (Column $column) {
$column- > append (Dashboard::extensions ())
})
$row- > column (4, function (Column $column) {
$column- > append (Dashboard::dependencies ())
})
})
})
}
}
Combined with the interface and code, we can see that the interface is mainly divided into several parts: header, description, two row, and the latter row contains three column modules. The specific code is placed in the Dashboard code, as follows:
Namespace Encore\ Admin\ Controllers
Use Encore\ Admin\ Admin
Class Dashboard
{
/ * *
* @ return\ Illuminate\ Contracts\ View\ Factory |\ Illuminate\ View\ View
* /
Public static function title ()
{
Return view ('admin::dashboard.title')
}
/ * *
* @ return\ Illuminate\ Contracts\ View\ Factory |\ Illuminate\ View\ View
* /
Public static function environment ()
{
$envs = [
['name' = >' PHP version', 'value' = >' PHP/'.PHP_VERSION]
['name' = >' Laravel version', 'value' = > app ()-> version ()]
['name' = >' CGI', 'value' = > php_sapi_name ()]
['name' = >' Uname', 'value' = > php_uname ()]
['name' = >' Server', 'value' = > array_get ($_ SERVER,' SERVER_SOFTWARE')]
['name' = >' Cache driver', 'value' = > config (' cache.default')]
['name' = >' Session driver', 'value' = > config (' session.driver')]
['name' = >' Queue driver', 'value' = > config (' queue.default')]
['name' = >' Timezone', 'value' = > config (' app.timezone')]
['name' = >' Locale', 'value' = > config (' app.locale')]
['name' = >' Env', 'value' = > config (' app.env')]
['name' = >' URL', 'value' = > config (' app.url')]
]
Return view ('admin::dashboard.environment', compact (' envs'))
}
/ * *
* @ return\ Illuminate\ Contracts\ View\ Factory |\ Illuminate\ View\ View
* /
Public static function extensions ()
{
$extensions = [
'helpers' = > [
'name' = >' laravel-admin-ext/helpers'
'link' = >' https://github.com/laravel-admin-extensions/helpers',
'icon' = >' gears'
]
'log-viewer' = > [
'name' = >' laravel-admin-ext/log-viewer'
'link' = >' https://github.com/laravel-admin-extensions/log-viewer',
'icon' = >' database'
]
'backup' = > [
'name' = >' laravel-admin-ext/backup'
'link' = >' https://github.com/laravel-admin-extensions/backup',
'icon' = >' copy'
]
'config' = > [
'name' = >' laravel-admin-ext/config'
'link' = >' https://github.com/laravel-admin-extensions/config',
'icon' = >' toggle-on'
]
'api-tester' = > [
'name' = >' laravel-admin-ext/api-tester'
'link' = >' https://github.com/laravel-admin-extensions/api-tester',
'icon' = >' sliders'
]
'media-manager' = > [
'name' = >' laravel-admin-ext/media-manager'
'link' = >' https://github.com/laravel-admin-extensions/media-manager',
'icon' = >' file'
]
'scheduling' = > [
'name' = >' laravel-admin-ext/scheduling'
'link' = >' https://github.com/laravel-admin-extensions/scheduling',
'icon' = >' clock-o'
]
'reporter' = > [
'name' = >' laravel-admin-ext/reporter'
'link' = >' https://github.com/laravel-admin-extensions/reporter',
'icon' = >' bug'
]
'translation' = > [
'name' = >' laravel-admin-ext/translation'
'link' = >' https://github.com/laravel-admin-extensions/translation',
'icon' = >' language'
]
]
Foreach ($extensions as & $extension) {
$name = explode ('/', $extension ['name'])
$extension ['installed'] = array_key_exists (end ($name), Admin::$extensions)
}
Return view ('admin::dashboard.extensions', compact (' extensions'))
}
/ * *
* @ return\ Illuminate\ Contracts\ View\ Factory |\ Illuminate\ View\ View
* /
Public static function dependencies ()
{
$json = file_get_contents (base_path ('composer.json'))
$dependencies = json_decode ($json, true) ['require']
Return view ('admin::dashboard.dependencies', compact (' dependencies'))
}
}
In this way, we organize the code in blocks. Specific layout category: class Content implements Renderable
Other static resource files are placed in the / public/vendor/laravel-admin directory
Disable the create button
$grid- > disableCreateButton ()
Disable paging bar
$grid- > disablePagination ()
Disable query filter
$grid- > disableFilter ()
Disable the export data button
$grid- > disableExport ()
Disable row action column
$grid- > disableActions ()
Set paging selector options
$grid- > perPages ([10, 20, 30, 40, 50])
By default, model-grid has two line operations to edit and delete, which can be turned off in the following ways:
$grid- > actions (function ($actions) {
/ / hide the delete button
$actions- > disableDelete ()
/ / hide the modify button
$actions- > disableEdit ()
})
If you have a custom action button, you can add it in the following ways:
$grid- > actions (function ($actions) {
/ / append an operation
$actions- > append ('')
/ / prepend an operation
$actions- > prepend ('')
})
Get the primary key information or an array of the current row
$grid- > actions (function ($actions) {
/ / data array of the current row
$row = $actions- > row
/ / get the current row primary key value
$id = $actions- > getKey ()
})
The copy code currently implements the function of batch deletion by default. If you want to turn off the batch delete operation:
$grid- > tools (function ($tools) {
$tools- > batch (function ($batch) {
$batch- > disableDelete ()
})
})
Query filtering Filter:
$grid- > filter (function ($query) {
/ / remove the default id filter
$query- > disableIdFilter ()
$query- > like ('title',' article title')
$query- > equal ('cate_id',' belongs to category')-> select (
ArticleCategories::pluck ('name',' id')
)
})
Some tips for form:
$form- > text ('from',' article source')-> rules ('required') / / you can add rules verification rules
$form- > image ('thumb',' article thumbnail')-> uniqueName ()
-> move ('upload/article/'. Date ("Ymd"))
-> options (['overwriteInitial' = > true]); / / represents a new image to replace and modify a picture
-> uniqueName () / / is a random name
/ / callback before saving
$form- > saving (function (Form $form) {
})
/ / callback after saving
$form- > saved (function (Form $form) {
})
Set the action for form submission
$form- > setAction ('admin/users')
Get the id in URL
$shopId = request ()-> route ()-> parameter ('shop')
When adding operation, the store name cannot be duplicated with other data in the database
When it is a modification operation, the store name cannot be duplicated with other data in the database except itself.
If ($shopId) {which is a good http://www.bhnnkyy120.com/ for Wuxi abortion Hospital
$form- > text ('shop_name',' store name')
-> rules ("required | unique:shops,shop_name, {$shopId}, id")
} else {
$form- > text ('shop_name',' store name')
-> rules ("required | unique:shops")
}
When entering the grid table, the default id is in reverse order
$grid- > model ()-> orderBy ('id',' desc')
Upload multiple images
Yesterday, a friend in the development of a feature, because the need to upload multiple images, asked me Laravel_admin how to do multiple picture upload, so I also view the document, but the official document basically did not talk about, and finally found outside the Internet, today to share with you about the use of tips.
We can refer to multiple images and upload them in the form as follows:
$form- > multipleImage ('images',' album')-> help ('Please upload picture format')-> removable ()
But when we use the removeable () method, we need to be aware that the MessageBag method cannot be used in the form form.
Then in the data model, we must define two methods as follows:
Public function getLogoAttribute ($value)
{
Return explode (',', $value)
}
Public function setLogoAttribute ($value)
{
$this- > attributes ['images'] = implode (',', $value)
}
After completing the above operations, we have successfully configured the upload of multiple images.
At this point, I believe you have a deeper understanding of "how to use the Laravel admin background management plug-in". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.