class UserController extends Controller
{
+ public function search(Request $request) {
+ $validatedData = $request->validate([
+ 'phrase' => 'string|nullable',
+ ]);
+
+ $users = User::query();
+ if (!empty($validatedData['phrase'])) {
+ $users = $users->where('username', 'LIKE', '%'.$validatedData['phrase'].'%')
+ ->orWhere('nickname', 'LIKE', '%'.$validatedData['phrase'].'%');
+ }
+ $users = $users->limit(5);
+ return $users->get()->toJson();
+ }
+
public function setLanguage(Request $request) {
$user = $request->user();
if (!$user) return;
return $user->toJson();
}
+ public function setNickname(Request $request, User $user) {
+ $this->authorize('setNickname', $user);
+
+ $validatedData = $request->validate([
+ 'nickname' => 'string',
+ ]);
+
+ $user->nickname = $validatedData['nickname'];
+ $user->update();
+
+ UserChanged::dispatch($user);
+
+ return $user->toJson();
+ }
+
public function setStreamLink(Request $request, User $user) {
$this->authorize('setStreamLink', $user);
public function single(Request $request, $id) {
$user = User::findOrFail($id);
$this->authorize('view', $user);
+ $user->append('random_quote');
+ $user->load('participation');
+ $user->load('participation.tournament');
+ $user->loadCount('round_first');
+ $user->loadCount('round_second');
+ $user->loadCount('round_third');
+ $user->loadCount('tournament_first');
+ $user->loadCount('tournament_second');
+ $user->loadCount('tournament_third');
return $user->toJson();
}