File tree Expand file tree Collapse file tree 3 files changed +41
-54
lines changed
Expand file tree Collapse file tree 3 files changed +41
-54
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ /**
6+ * NOTICE OF LICENSE.
7+ *
8+ * UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
9+ * The details is bundled with this project in the file LICENSE.txt.
10+ *
11+ * @project UNIT3D Community Edition
12+ *
13+ * @author Roardom <roardom@protonmail.com>
14+ * @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
15+ */
16+
17+ namespace App \Data \Staff ;
18+
19+ use App \Attributes \FromCurrentUserId ;
20+ use App \Models \User ;
21+ use Spatie \LaravelData \Attributes \Validation \Exists ;
22+ use Spatie \LaravelData \Attributes \Validation \Max ;
23+ use Spatie \LaravelData \Data ;
24+
25+ class BanData extends Data
26+ {
27+ public function __construct (
28+ #[Max(65535 )]
29+ public string $ banReason ,
30+ #[Exists(User::class, 'id ' )]
31+ public int $ ownedBy ,
32+ #[FromCurrentUserId]
33+ public int $ createdBy ,
34+ ) {
35+ }
36+ }
Original file line number Diff line number Diff line change 1616
1717namespace App \Http \Controllers \Staff ;
1818
19+ use App \Data \Staff \BanData ;
1920use App \Http \Controllers \Controller ;
2021use App \Http \Requests \Staff \StoreBanRequest ;
2122use App \Models \Ban ;
2425use App \Notifications \UserBan ;
2526use App \Services \Unit3dAnnounce ;
2627use Exception ;
28+ use Illuminate \Container \Attributes \CurrentUser ;
2729
2830/**
2931 * @see \Tests\Todo\Feature\Http\Controllers\Staff\BanControllerTest
@@ -45,10 +47,9 @@ public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\Vie
4547 *
4648 * @throws Exception
4749 */
48- public function store (StoreBanRequest $ request ): \Illuminate \Http \RedirectResponse
50+ public function store (BanData $ data , #[CurrentUser] User $ staff ): \Illuminate \Http \RedirectResponse
4951 {
50- $ user = User::findOrFail ($ request ->string ('owned_by ' ));
51- $ staff = $ request ->user ();
52+ $ user = User::findOrFail ($ data ->ownedBy );
5253
5354 abort_if ($ user ->group ->is_modo || $ staff ->is ($ user ), 403 );
5455
@@ -57,7 +58,7 @@ public function store(StoreBanRequest $request): \Illuminate\Http\RedirectRespon
5758 'can_download ' => 0 ,
5859 ]);
5960
60- $ ban = Ban::create ([ ' created_by ' => $ staff -> id ] + $ request -> validated ());
61+ $ ban = Ban::create ($ data -> toArray ());
6162
6263 cache ()->forget ('user: ' .$ user ->passkey );
6364
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments