PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, April 20, 2022

[FIXED] How to add field in laravel backpack add user form

 April 20, 2022     laravel, laravel-backpack     No comments   

Issue

I need to add some fields in the user create page in admin panel. enter image description here

This page includes only name field, I need to add first name and last name field. What is the way...


Solution

You need to do the following:

  1. Create your own class for the User CRUD panel:
<?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. Then tell Backpack to use your class instead of the one from the permission manager package. In file 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');
});

The second group is the one that tells the router to register your controller App\Http\Controllers\Admin\UserCrudController instead of the one from the package. The first group takes care to register the permissions and roles controllers from the package, so there is no need to do any extra steps for them.



Answered By - o15a3d4l11s2
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing