Untitled

mail@pastecode.io avatar
unknown
javascript
7 months ago
1.2 kB
1
Indexable
Never
class PlayerController extends Controller
{
    public function __construct(private PlayerService $playerService)
    {
    }
    private function getPlayer(): Player
    {
        return $this->find(Auth::id());
    }

    public function grantTitle(Request $request)
    {
        $response = $this->playerService->grantTitle(
            $request->user(),
            $request->get('title')
        );

        return response()->json($response);
    }

    public function setActiveTitle(Request $request)
    {
        $response = $this->playerService->setActiveTitle(
            $request->user(),
            $request->get('title')
        );

        return response()->json($response);
    }

    public function getProfile()
    {
        // $player = $this->playerService->getProfile(Auth::id());
        $player = $this->getPlayer();

        return response()->json(new PlayerResource($player));
    }

    public function getUnlockedTitles(Request $request)
    {
        $player = Auth::user();
        $unlockedTitles = new TitlesResourceCollection($player->unlockedTitles);

        return response()->json(['unlockedTitles' => $unlockedTitles]);
    }
}
Leave a Comment