]> git.localhorst.tv Git - alttp.git/blob - app/Http/Controllers/DiscordChannelController.php
protocol chat bot messages
[alttp.git] / app / Http / Controllers / DiscordChannelController.php
1 <?php
2
3 namespace App\Http\Controllers;
4
5 use App\Models\DiscordChannel;
6 use App\Models\DiscordGuild;
7 use Illuminate\Http\Request;
8
9 class DiscordChannelController extends Controller
10 {
11
12         public function search(Request $request, $guild_id) {
13                 $guild = DiscordGuild::where('guild_id', '=', $guild_id)->firstOrFail();
14                 $this->authorize('view', $guild);
15
16                 $validatedData = $request->validate([
17                         'parents' => 'array|nullable',
18                         'parents.*' => 'string',
19                         'phrase' => 'string|nullable',
20                         'types' => 'array|nullable',
21                         'types.*' => 'integer',
22                 ]);
23
24                 $channels = $guild->channels();
25                 if (!empty($validatedData['parents'])) {
26                         $channels = $channels->whereIn('parent', $validatedData['parents']);
27                 }
28                 if (!empty($validatedData['phrase'])) {
29                         $channels = $channels->where('name', 'LIKE', '%'.$validatedData['phrase'].'%');
30                 }
31                 if (!empty($validatedData['types'])) {
32                         $channels = $channels->whereIn('type', $validatedData['types']);
33                 }
34                 return $channels->get()->toJson();
35         }
36
37         public function single(Request $request, $channel_id) {
38                 $channel = DiscordChannel::where('channel_id', '=', $channel_id)->firstOrFail();
39                 $this->authorize('view', $channel);
40                 return $channel->toJson();
41         }
42
43 }