如何在 laravel 背包添加用户表单中添加字段

How to add field in laravel backpack add user form

我需要在管理面板的用户创建页面中添加一些字段。

本页仅包含name字段,我需要添加first namelast name字段。 有什么方法...

您需要执行以下操作:

  1. 为用户 CRUD 面板创建您自己的 class:
<?php

namespace App\Http\Controllers\Admin;

use Backpack\PermissionManager\app\Http\Controllers\UserCrudController as BackpackUserCrudController;

class UserCrudController extends BackpackUserCrudController
{
    public function setupListOperation()
    {
        // This takes care to add all fields from the package. If you need some field removed you could use CRUD::removeField
        parent::setupListOperation();

        CRUD::field('first_name')->type('text');
        // Any other fields that you need
    }

    public function setupUpdateOperation()
    {
        // This takes care to add all fields from the package. If you need some field removed you could use CRUD::removeField
        parent::setupUpdateOperation();

        CRUD::field('first_name')->type('text');
        // Any other fields that you need
    }
}
  1. 然后告诉 Backpack 使用您的 class 而不是权限管理器包中的那个。在文件 routes/backpack/permissionmanager.php:
<?php

/*
|--------------------------------------------------------------------------
| Backpack\PermissionManager Routes
|--------------------------------------------------------------------------
|
| This file is where you may define all of the routes that are
| handled by the Backpack\PermissionManager package.
|
*/

Route::group([
    'namespace' => 'Backpack\PermissionManager\app\Http\Controllers',
    'prefix' => config('backpack.base.route_prefix', 'admin'),
    'middleware' => ['web', backpack_middleware()],
], function () {
    Route::crud('permission', 'PermissionCrudController');
    Route::crud('role', 'RoleCrudController');
});

Route::group([
    'namespace' => 'App\Http\Controllers\Admin',
    'prefix' => config('backpack.base.route_prefix', 'admin'),
    'middleware' => ['web', backpack_middleware()],
], function () {
    Route::crud('user', 'UserCrudController');
});

第二组告诉路由器注册您的控制器App\Http\Controllers\Admin\UserCrudController而不是包装中的那组。第一组负责从包中注册权限和角色控制器,因此不需要为它们做任何额外的步骤。