geeklearners / laravel-admin
Laravel Admin Panel 生成器包
v0.1.3
2020-08-24 05:34 UTC
Requires
- laravelcollective/html: ^6.0@dev
This package is auto-updated.
Last update: 2024-09-24 15:12:25 UTC
README
此包以简单和可配置的方式设置管理面板。
安装
composer require geeklearners/laravel-admin
发布配置
php artisan vendor:publish --tag=geeklearners_admin
这将在配置文件夹中发布 admin.php
文件。
admin.php
中的自定义详情
prefix
用于路由的默认值设置为 admin
。 crud_classes
是包含需要生成 CRUD 的模型的数组。 base_admin_layout
用于指定用于渲染管理面板的基本布局。
- 所有 CRUD 操作都放置在
@section('admin_content')
内。因此,主要管理布局需要包含@yield('admin_content')
以渲染内容。
用法示例
use App\Http\Requests\StoreContactTypeRequest; use Geeklearners\Traits\ModelAdmin; use Illuminate\Database\Eloquent\Model; class ContactType extends Model { use ModelAdmin; protected $guarded = ['id']; /** * Form fields to be displayed during creation */ public static function formFields = [ 'name' => [ 'type' => 'text', 'class' => 'form-control' ], 'description' => [ 'type' => 'text', 'class' => 'form-control' ], 'status' => [ 'type' => 'select', 'class' => 'form-control', 'options' => ['1' => 'Active', '0' => 'Inactive'] ] ]; /** * Laravel FormRequest can be injected with the following key which of them will instantiated * at appropriate methods * 'store'=>................... * 'index'=>................... * 'update'=>.................. * 'delete'=>.................. */ public static $form_requests = [ 'store' => StoreContactTypeRequest::class ]; /** * List out the columns to include when listing the resources. * Its an associative array each of the keys receiving optional callback. * callback provides the complete row, which can be further customized. */ public static function colsToInclude() { return [ 'name' => function ($col) { return $col->name; }, 'description', 'status' ]; } /** * List out the additional columns to include when listing the resources. * Its an associative array each of the keys receiving optional callback. * callback provides the complete row, which can be further customized. */ public static function additionalColumns() { return ['Actions' => function ($col) { return "<a href='" . route('admin.edit', ['model' => 'contact-type', 'id' => $col->id]) . "' class='btn btn-success fa fa-edit'>Edit</a> | <form method='post' style='display:inline' action='" . route('admin.destroy', ['model' => 'contact-type', 'id' => $col->id]) . "'><input type='hidden' name='_method' value='delete'><input type='hidden' name='_token' value='" . csrf_token() . "'><input type='submit' value='Delete' class='btn btn-danger btn-sm'></form>"; }]; } }