Skip to content

Commit

Permalink
fixes #7 - adds support for Backpack v4
Browse files Browse the repository at this point in the history
  • Loading branch information
tabacitu committed Dec 3, 2019
1 parent 23ad400 commit a796a25
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 41 deletions.
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,38 @@ An admin interface to easily add/edit/remove users, using [Backpack for Laravel]
> Please **[subscribe to the Backpack Newsletter](http://backpackforlaravel.com/newsletter)** so you can find out about any security updates, breaking changes or major features. We send an email every 1-2 months.

## Install
## Install on Backpack v4 (Laravel 6)

1) In your terminal:

```bash
composer require eduardoarandah/usermanager
```

2) Use Backpack's CrudTrait on your User model:
```php
<?php namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
use Backpack\CRUD\app\Models\Traits\CrudTrait; // <----- this

/**
* Your User Model content
*/
```

4) [Optional] Add a menu item for it:

```bash
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```)


## Install on Backpack v3 (Laravel 5)

1) In your terminal:

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eduardoarandah/usermanager",
"description": "Users management interface for Laravel 5 using Backpack CRUD.",
"description": "Users management interface for Laravel 6 using Backpack CRUD.",
"keywords": [
"laravel backpack",
"backpack user management",
Expand All @@ -21,7 +21,7 @@
}
],
"require": {
"backpack/crud": "^3.4.0"
"backpack/crud": "^4.0.0"
},
"require-dev": {
"phpunit/phpunit" : "4.*",
Expand Down
82 changes: 50 additions & 32 deletions src/app/Http/Controllers/UserCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@

class UserCrudController extends CrudController
{
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation { store as traitStore; }
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation { update as traitUpdate; }
use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;

public function setup()
{
/*
|--------------------------------------------------------------------------
| BASIC CRUD INFORMATION
|--------------------------------------------------------------------------
*/
$this->crud->setModel(config('eduardoarandah.usermanager.user_model'));
$this->crud->setEntityNameStrings(trans('eduardoarandah::usermanager.user'), trans('eduardoarandah::usermanager.users'));
$this->crud->setRoute(config('backpack.base.route_prefix').'/user');
$this->crud->enableAjaxTable();
}

// Columns.
protected function setupListOperation()
{
$this->crud->setColumns([
[
'name' => 'name',
Expand All @@ -34,30 +35,18 @@ public function setup()
'type' => 'email',
]
]);
}

// Fields
$this->crud->addFields([
[
'name' => 'name',
'label' => trans('eduardoarandah::usermanager.name'),
'type' => 'text',
],
[
'name' => 'email',
'label' => trans('eduardoarandah::usermanager.email'),
'type' => 'email',
],
[
'name' => 'password',
'label' => trans('eduardoarandah::usermanager.password'),
'type' => 'password',
],
[
'name' => 'password_confirmation',
'label' => trans('eduardoarandah::usermanager.password_confirmation'),
'type' => 'password',
]
]);
protected function setupCreateOperation()
{
$this->crud->setValidation(StoreRequest::class);
$this->addFields();
}

protected function setupUpdateOperation()
{
$this->crud->setValidation(UpdateRequest::class);
$this->addFields();
}

/**
Expand All @@ -71,7 +60,7 @@ public function store(StoreRequest $request)
{
$this->handlePasswordInput($request);

return parent::storeCrud($request);
return $this->traitStore($request);
}

/**
Expand All @@ -85,9 +74,38 @@ public function update(UpdateRequest $request)
{
$this->handlePasswordInput($request);

return parent::updateCrud($request);
return $this->traitUpdate($request);
}

/**
* Add the fields needed in the Create and Update operations.
*/
protected function addFields()
{
$this->crud->addFields([
[
'name' => 'name',
'label' => trans('eduardoarandah::usermanager.name'),
'type' => 'text',
],
[
'name' => 'email',
'label' => trans('eduardoarandah::usermanager.email'),
'type' => 'email',
],
[
'name' => 'password',
'label' => trans('eduardoarandah::usermanager.password'),
'type' => 'password',
],
[
'name' => 'password_confirmation',
'label' => trans('eduardoarandah::usermanager.password_confirmation'),
'type' => 'password',
]
]);
}

/**
* Handle password input fields.
*
Expand Down
13 changes: 7 additions & 6 deletions src/routes/eduardoarandah/usermanager.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

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

0 comments on commit a796a25

Please sign in to comment.