push(Item::find($item)); } $col_items->forget(0); return $col_items; } protected $casts = [ 'metadata' => 'array', ]; public function bookings() { return $this->hasMany('App\Booking'); } public function category() { return \App\ItemCategory::find($this->category_id); } public function available() { return $this->quantity - $this->booked(); } public function booked() { $nbBooked = 0; foreach ($this->bookings() as $b) { $nbBooked = $nbBooked + $b->amount; } return $nbBooked; } }