An admin interface to easily add/edit/remove users, using Backpack for Laravel
Please subscribe to the Backpack Newsletter so you can find out about any security updates, breaking changes or major features. We send an email every 1-2 months.
- In your terminal:
composer require eduardoarandah/usermanager
- Add Backpack's CrudTrait on your User model:
By default: app/User.php
namespace App;
class BackpackUser extends User
{
use \Backpack\CRUD\app\Models\Traits\CrudTrait; // <--- Add this line
// ...
- [Optional] If your User model is NOT
App\User::class
or your users table is notusers
, you should publish this package's config file and correct those assumptions in theconfig/eduardoarandah/usermanager.php
file. To publish file, run:
php artisan vendor:publish --provider="EduardoArandaH\UserManager\UserManagerServiceProvider" --tag='config'
- [Optional] Add a sidebar link
php artisan backpack:add-sidebar-content "<li class='nav-item'><a class='nav-link' href='{{ backpack_url('user') }}'><i class='nav-icon la la-user'></i> <span>Users</span></a></li>"
(alternatively, manually add an item in resources/views/vendor/backpack/base/inc/sidebar_content.blade.php
or menu.blade.php
)
- In your terminal:
composer require eduardoarandah/usermanager
- Add Backpack's CrudTrait on your User model:
By default: app/Models/BackpackUser.php
namespace App\Models;
use App\User;
use Backpack\CRUD\app\Models\Traits\InheritsRelationsFromParentModel;
use Backpack\CRUD\app\Notifications\ResetPasswordNotification as ResetPasswordNotification;
use Illuminate\Notifications\Notifiable;
use Backpack\CRUD\app\Models\Traits\CrudTrait; <--- Add this line
class BackpackUser extends User
{
use InheritsRelationsFromParentModel;
use Notifiable;
use CrudTrait; <--- Add this line
...
- [Optional] Add a sidebar link
php artisan backpack:add-sidebar-content "<li class='nav-item'><a class='nav-link' href='{{ backpack_url('user') }}'><i class='nav-icon fa fa-user'></i> <span>Users</span></a></li>"
(alternatively, manually add an item in resources/views/vendor/backpack/base/inc/sidebar_content.blade.php
or menu.blade.php
)
- In your terminal:
composer require eduardoarandah/usermanager
- For Laravel <5.5, add the service provider to your config/app.php file:
EduardoArandaH\UserManager\UserManagerServiceProvider::class,
- Use the following traits on your User model:
<?php namespace App;
use Backpack\CRUD\CrudTrait; // <------------------------------- this one
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use CrudTrait; // <----- this
/**
* Your User Model content
*/
- [Optional] Add a menu item for it:
php artisan backpack:base:add-sidebar-content "<li><a href='{{ backpack_url('user') }}'><i class='fa fa-user'></i> <span>Users</span></a></li>"
(alternatively, manually add an item in resources/views/vendor/backpack/base/inc/sidebar_content.blade.php
or menu.blade.php
)
When you need more control on your user model, the best way is copying the code.
You can even make your own CRUD controller with php artisan backpack:crud user
and simply add handlePasswordInput
addFields
methods in src/app/Http/Controllers/UserCrudController
. See code
Go to vendor/eduardoarandah/usermanager/src
and copy:
-
Route:
routes/eduardoarandah/usermanager.php
in yourroutes/web.php
file -
Controller
app/Http/Controllers/UserCrudController.php
inside yourapp/Http/Controllers
folder -
Requests
app/Http/Requests/*
inside yourapp/Http/Controllers
folder -
In UserCrudController set the model, example:
$this->crud->setModel('App\User'));
-
In every file, replace my namespace
EduardoArandaH\UserManager\app\Http\Requests
forApp\Http\Requests
Now you can remove the package with composer:
composer remove eduardoarandah/usermanager
https://laravel-backpack.readme.io/docs/crud-fields
https://laravel-backpack.readme.io/docs/crud-columns-types
To successfully use this package after you upgrade your project from Backpack 4.0 to Backpack 4.1, you need to:
- require version
^3.0
of this package by changing yourcomposer.json
file or runningcomposer require eduardoarandah/usermanager:"^3.0"
; - (most likely) change the user model in the usermanager config file from
App\Models\BackpackUser::class
toApp\User::class
; - (less likely) if you've extended the UserCrudController in this package and you've modified the
handlePasswordInput()
function, you also need to take account that the crud request in now fetched using setters and getters instead of directly as a property; take a closer look at Step 11 in the Backpack 4.1 upgrade guide, or look at the new code in this package for inspiration;