Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

usamaahmed's avatar

Add user approve/pending button in laravel voyager

HI I,m new to laravel, I want to add a user approve pending button in voyager admin Users section This is my controller to stop users from login

0 likes
1 reply
tisuchi's avatar

@usamaahmed This could be one of the approaches.

  1. Add a new column is_approved in the users table and then run php artisan migrate

  2. Modify the User model to add a scope that allows you to filter users based on their approval status:


    public function scopeApproved($query)
    {
        return $query->where('is_approved', true);
    }

    public function scopePending($query)
    {
        return $query->where('is_approved', false);
    }

  1. Create a new custom action button in the User BREAD, this button will change the approval status of the user.
    use TCG\Voyager\Actions\AbstractAction;
    class ApproveUser extends AbstractAction
    {
        public function getTitle()
        {
            return 'Approve';
        }
        public function getIcon()
        {
            return 'voyager-check';
        }
        public function getPolicy()
        {
            return 'read';
        }
        public function getAttributes()
        {
            return [
                'class' => 'btn btn-success',
            ];
        }
        public function getDefaultRoute()
        {
            return route('approve-user', $this->data->{$this->data->getKeyName()});
        }
        public function shouldActionDisplayOnDataType()
        {
            return $this->data->is_approved === false;
        }
    }
  1. Register your custom action in the UserServiceProvider
    use App\Actions\ApproveUser;
    use TCG\Voyager\Voyager;

    public function boot(Voyager $voyager)
    {
        $voyager->addAction(ApproveUser::class);
    }

2 likes

Please or to participate in this conversation.