@@ -180,6 +180,7 @@ use App\Events\GuestIsCheckedIn;
180180use App\Events\GuestIsCheckedOut;
181181use App\Events\HotelCreated;
182182use Illuminate\Database\Schema\Blueprint;
183+ use Illuminate\Support\Collection;
183184use Illuminate\Support\Facades\DB;
184185use Illuminate\Support\Facades\Schema;
185186use Patchlevel\EventSourcing\Aggregate\Uuid;
@@ -194,41 +195,36 @@ final class HotelProjection
194195{
195196 use SubscriberUtil;
196197
197- /** @return list <array {id: string, name: string, guests: int} > */
198- public function getHotels(): array
198+ /** @return Collection <array {id: string, name: string, guests: int} > */
199+ public function getHotels(): Collection
199200 {
200- return DB::select('select id, name, guests from ' . $this->table());
201+ return DB::table( $this->table())->get( );
201202 }
202203
203204 #[Subscribe(HotelCreated::class)]
204205 public function handleHotelCreated(HotelCreated $event): void
205206 {
206- DB::insert(
207- "insert into {$this->table()} (id, name, guests) values (?, ?, ?)",
208- [
209- $event->id->toString(),
210- $event->hotelName,
211- 0,
212- ],
213- );
207+ DB::table($this->table())->insert([
208+ 'id' => $event->id->toString(),
209+ 'name' => $event->hotelName,
210+ 'guests' => 0,
211+ ]);
214212 }
215213
216214 #[Subscribe(GuestIsCheckedIn::class)]
217215 public function handleGuestIsCheckedIn(Uuid $hotelId): void
218216 {
219- DB::update(
220- "update {$this->table()} set guests = guests + 1 where id = ?",
221- [$hotelId->toString()],
222- );
217+ DB::table($this->table())
218+ ->where('id', $hotelId->toString())
219+ ->increment('guests');
223220 }
224221
225222 #[Subscribe(GuestIsCheckedOut::class)]
226223 public function handleGuestIsCheckedOut(Uuid $hotelId): void
227224 {
228- DB::update(
229- "update {$this->table()} set guests = guests - 1 where id = ?",
230- [$hotelId->toString()],
231- );
225+ DB::table($this->table())
226+ ->where('id', $hotelId->toString())
227+ ->decrement('guests');
232228 }
233229
234230 #[Setup]
0 commit comments