I save a new entry and then retrieve the data from the database again. But the foreach only shows the number of entries it had before. So there were 5 before and after creating a new entry there are still 5, but the variable has 6 entries. count($bookings) show 6
laravel 11
livewire 3
public function save(){
$this->validate([
'value' => 'required',
'comment' => 'required',
'booking_date' => 'required',
]);
$checkout = new Checkout();
$checkout->group_id = $this->group->id;
$checkout->created_by = Member::where('user_id', '=', Auth::user()->id)
->where('group_id', '=', $this->group->id)
->first()
->id;
$checkout->value = $this->value;
$checkout->comment = $this->comment;
$checkout->type = $this->type;
$checkout->booking_date = $this->booking_date;
if($checkout->save()){
$this->addCheckoutModal = false;
$this->notification()->send([
'icon' => 'success',
'title' => 'Buchung angelegt',
'description' => 'Buchung wurde erfolgreich angelegt.',
]);
$this->bookings = Checkout::where('group_id', '=', $this->group->id)->get();
}
}
<ul class="grid grid-cols-1 gap-4">
{{ count($bookings) }}
@foreach ( $bookings as $booking)
<li wire:key="booking-{{ $booking->id }}" class="flex justify-between items-center p-3 bg-slate-100 border-2 border-slate-200 rounded-lg">
<div class="flex gap-3">
@if( $booking->type == 'in' )
<x-tabler-database-plus class="h-8 w-8 stroke-1-5 text-emerald-400" />
@else
<x-tabler-database-minus class="h-8 w-8 stroke-1-5 text-rose-400" />
@endif
<div class="flex flex-col">
<span class="text-xs">{{ \Carbon\Carbon::parse($booking->booking_date)->format('d.m.Y') }}</span>
<span>{{ $booking->comment }}</span>
</div>
</div>
<div>
<span class="font-semibold text-lg">{{ ($booking->type == 'out') ? '-' : '' }}{{ number_format($booking->value, 2, ',', '.') }} €</span>
</div>
@endforeach
</ul>