Level 70
@usamaahmed This could be one of the approaches.
-
Add a new column
is_approvedin theuserstable and then runphp artisan migrate -
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);
}
- 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;
}
}
- 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