3 namespace App\Http\Controllers;
5 use App\Models\DiscordChannel;
6 use App\Models\DiscordGuild;
7 use Illuminate\Http\Request;
9 class DiscordChannelController extends Controller
12 public function search(Request $request, $guild_id) {
13 $guild = DiscordGuild::where('guild_id', '=', $guild_id)->firstOrFail();
14 $this->authorize('view', $guild);
16 $validatedData = $request->validate([
17 'parents' => 'array|nullable',
18 'parents.*' => 'string',
19 'phrase' => 'string|nullable',
20 'types' => 'array|nullable',
21 'types.*' => 'integer',
24 $channels = $guild->channels();
25 if (!empty($validatedData['parents'])) {
26 $channels = $channels->whereIn('parent', $validatedData['parents']);
28 if (!empty($validatedData['phrase'])) {
29 $channels = $channels->where('name', 'LIKE', '%'.$validatedData['phrase'].'%');
31 if (!empty($validatedData['types'])) {
32 $channels = $channels->whereIn('type', $validatedData['types']);
34 return $channels->get()->toJson();