Skip to content

Commit adc7eb4

Browse files
committed
update projector example
1 parent 3a6b94b commit adc7eb4

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

docs/pages/getting_started.md

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ use App\Events\GuestIsCheckedIn;
180180
use App\Events\GuestIsCheckedOut;
181181
use App\Events\HotelCreated;
182182
use Illuminate\Database\Schema\Blueprint;
183+
use Illuminate\Support\Collection;
183184
use Illuminate\Support\Facades\DB;
184185
use Illuminate\Support\Facades\Schema;
185186
use 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

Comments
 (0)