]> git.localhorst.tv Git - alttp.git/blob - app/Http/Controllers/DiscordGuildController.php
basic content editing
[alttp.git] / app / Http / Controllers / DiscordGuildController.php
1 <?php
2
3 namespace App\Http\Controllers;
4
5 use App\Models\DiscordGuild;
6 use Illuminate\Http\Request;
7
8 class DiscordGuildController extends Controller
9 {
10
11         public function search(Request $request) {
12                 $validatedData = $request->validate([
13                         'phrase' => 'string|nullable',
14                 ]);
15
16                 $guilds = DiscordGuild::query();
17                 if (!$request->user()->can('viewAny', DiscordGuild::class)) {
18                         $guilds = $guilds->where('owner', '=', $request->user()->id);
19                 }
20                 if (!empty($validatedData['phrase'])) {
21                         $guilds = $guilds->where('name', 'LIKE', '%'.$validatedData['phrase'].'%');
22                 }
23                 $guilds = $guilds->limit(5);
24                 return $guilds->get()->toJson();
25         }
26
27         public function single(Request $request, $guild_id) {
28                 $guild = DiscordGuild::where('guild_id', '=', $guild_id)->firstOrFail();
29                 $this->authorize('view', $guild);
30                 return $guild->toJson();
31         }
32
33 }