3 namespace App\Http\Controllers;
5 use App\Models\DiscordGuild;
6 use Illuminate\Http\Request;
8 class DiscordGuildController extends Controller
11 public function search(Request $request) {
12 $validatedData = $request->validate([
13 'phrase' => 'string|nullable',
16 $guilds = DiscordGuild::query();
17 if (!$request->user()->can('viewAny', DiscordGuild::class)) {
18 $guilds = $guilds->where('owner', '=', $request->user()->id);
20 if (!empty($validatedData['phrase'])) {
21 $guilds = $guilds->where('name', 'LIKE', '%'.$validatedData['phrase'].'%');
23 $guilds = $guilds->limit(5);
24 return $guilds->get()->toJson();
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();