How to use a custom operation inside PermissionManager

So you want to add a new operation to the UserCrudController, the one that our PermissionManager addon provides? Here’s how you can do...

Karan Datwani
Karan Datwani
Share:

So you want to add a new operation to the UserCrudController, the one that our PermissionManager addon provides? Here’s how you can do that.

In this article, we assume:

  • You already have that operation created and working fine; If you do not, take a look at this tutorial, where we teach you how to create one;
  • You already have PermissionManager installed;

Let’s go ahead.

Steps:

1. Create a UserCrudController that extends the one from the package.

We will create a UserCrudController extending Backpack Permission Manager’s UserCrudController. That way, we keep getting all updates to the package.

//app/Http/Controllers/Admin/UserCrudController.php

<?php

namespace App\Http\Controllers\Admin;

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

class UserCrudController extends CrudController
{
    
}

2. Bind it.

Then in AppServiceProvider, we'll tell Laravel to use our new UserCrudController, instead of the one provided by Permission Manager:

//app/Providers/AppServiceProvider.php
public function register(){
+    $this->app->bind(
+    \Backpack\PermissionManager\app\Http\Controllers\UserCrudController::class,
+    \App\Http\Controllers\Admin\UserCrudController::class
+    );
}

3. Add your operation to your extended UserCrudController.

Final Step, use your operation inside UserCrudController. Here, I'm using EmailOperation created in our previous tutorial.

class UserCrudController extends CrudController{
+    use \App\Http\Controllers\Admin\Operations\EmailOperation;
}

That’s it, really.😀

Result:

Thanks for reading 😀 – I hope you learned something new. Let us know what you think in the comments below.

Want to receive more articles like this?

Subscribe to our "Article Digest". We'll send you a list of the new articles, every week, month or quarter - your choice.

Reactions & Comments

What do you think about this?

Latest Articles

Wondering what our community has been up to?