Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

pixelfed/pixelfed

6813 stars
1 code files
View pixelfed/pixelfed on GitHub

app/Console/Commands/UserAdmin.php

Open in GitHub
use Illuminate\Console\Command;
use App\User;
 
class UserAdmin extends Command
{
protected $signature = 'user:admin {id}';
 
protected $description = 'Make a user an admin, or remove admin privileges.';
 
public function __construct()
{
parent::__construct();
}
 
public function handle()
{
$id = $this->argument('id');
$user = User::whereUsername($id)->orWhere('id', $id)->first();
if(!$user) {
$this->error('Could not find any user with that username or id.');
exit;
}
$this->info('Found username: ' . $user->username);
$state = $user->is_admin ? 'Remove admin privileges from this user?' : 'Add admin privileges to this user?';
$confirmed = $this->confirm($state);
if(!$confirmed) {
exit;
}
 
$user->is_admin = !$user->is_admin;
$user->save();
$this->info('Successfully changed permissions!');
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.