roomRepository = $roomRepository; } public function index(): JsonResponse { $rooms = $this->roomRepository->all(); return response()->json( $rooms->toArray() ); } public function store(RoomFactory $roomFactory): JsonResponse { $this->validate(request(), [ 'name' => 'required|string|unique:rooms,name' ]); $room = $roomFactory->create( request()->post('name') ); return response()->json( $room->toArray() ); } }