-
app/Jobs/BanUser.php
Open in GitHubuse 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 GitHubuse 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(); } //