3 namespace App\Http\Controllers;
5 use App\Events\UserChanged;
7 use Illuminate\Http\Request;
9 class UserController extends Controller
12 public function setLanguage(Request $request) {
13 $user = $request->user();
16 $validatedData = $request->validate([
17 'language' => 'required|in:de,en',
20 $user->locale = $validatedData['language'];
23 return $user->toJson();
26 public function setStreamLink(Request $request, User $user) {
27 $this->authorize('setStreamLink', $user);
29 $validatedData = $request->validate([
30 'stream_link' => 'required|url',
33 $user->stream_link = $validatedData['stream_link'];
36 UserChanged::dispatch($user);
38 return $user->toJson();
41 public function single(Request $request, $id) {
42 $user = User::findOrFail($id);
43 $this->authorize('view', $user);
44 $user->load('participation');
45 $user->load('participation.tournament');
46 $user->loadCount('round_first');
47 $user->loadCount('round_second');
48 $user->loadCount('round_third');
49 $user->loadCount('tournament_first');
50 $user->loadCount('tournament_second');
51 $user->loadCount('tournament_third');
52 return $user->toJson();