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 setNickname(Request $request, User $user) {
27 $this->authorize('setNickname', $user);
29 $validatedData = $request->validate([
30 'nickname' => 'string',
33 $user->nickname = $validatedData['nickname'];
36 UserChanged::dispatch($user);
38 return $user->toJson();
41 public function setStreamLink(Request $request, User $user) {
42 $this->authorize('setStreamLink', $user);
44 $validatedData = $request->validate([
45 'stream_link' => 'required|url',
48 $user->stream_link = $validatedData['stream_link'];
51 UserChanged::dispatch($user);
53 return $user->toJson();
56 public function single(Request $request, $id) {
57 $user = User::findOrFail($id);
58 $this->authorize('view', $user);
59 $user->load('participation');
60 $user->load('participation.tournament');
61 $user->loadCount('round_first');
62 $user->loadCount('round_second');
63 $user->loadCount('round_third');
64 $user->loadCount('tournament_first');
65 $user->loadCount('tournament_second');
66 $user->loadCount('tournament_third');
67 return $user->toJson();