Skip to main content

devhub-az/devhub

24 stars
2 code files
View devhub-az/devhub on GitHub

app/Jobs/BanUser.php

Open in GitHub
use App\Models\User;
use Carbon\Carbon;
 
final class BanUser
{
private User $user;
 
public function __construct(User $user)
{
$this->user = $user;
}
 
public function handle(): User
{
$this->user->banned_at = Carbon::now();
$this->user->save();
 
return $this->user;
}
}

app/Http/Controllers/Admin/UsersController.php

Open in GitHub
use App\Jobs\BanUser;
use App\Models\User;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Http\RedirectResponse;
 
class UsersController extends Controller
{
//
public function ban(User $user): RedirectResponse
{
try {
$this->authorize(AuthorPolicy::BAN, $user);
} catch (AuthorizationException $e) {
}
 
$this->dispatchNow(new BanUser($user));
 
return back();
}
//