-
app/Http/Controllers/Staff/BanController.php
Open in GitHubuse App\Http\Controllers\Controller; use App\Mail\BanUser; use App\Models\Ban; use App\Models\Group; use App\Models\User; use Illuminate\Http\Request; use Illuminate\Support\Facades\Mail; class BanController extends Controller { // public function store(Request $request, $username) { $user = User::where('username', '=', $username)->firstOrFail(); $staff = $request->user(); $bannedGroup = \cache()->rememberForever('banned_group', fn () => Group::where('slug', '=', 'banned')->pluck('id')); \abort_if($user->group->is_modo || $request->user()->id == $user->id, 403); $user->group_id = $bannedGroup[0]; $user->can_upload = 0; $user->can_download = 0; $user->can_comment = 0; $user->can_invite = 0; $user->can_request = 0; $user->can_chat = 0; $ban = new Ban(); $ban->owned_by = $user->id; $ban->created_by = $staff->id; $ban->ban_reason = $request->input('ban_reason'); $v = \validator($ban->toArray(), [ 'ban_reason' => 'required', ]); if ($v->fails()) { return \redirect()->route('users.show', ['username' => $user->username]) ->withErrors($v->errors()); } $user->save(); $ban->save(); // Send Email Mail::to($user->email)->send(new BanUser($user->email, $ban)); return \redirect()->route('users.show', ['username' => $user->username]) ->withSuccess('User Is Now Banned!'); } // }
-
app/Mail/BanUser.php
Open in GitHubuse Illuminate\Mail\Mailable; class BanUser extends Mailable { public function __construct(public $email, public $ban) { } public function build() { return $this->markdown('emails.ban') ->subject('You Have Been Banned - '.\config('other.title')); } }
-
resources/views/emails/ban.blade.php
Open in GitHub@component('mail::message') # @lang('email.banned-header')! **Reason:** {{ $ban->ban_reason }} *@lang('email.banned-footer')* @endcomponent