belongsTo(Product::class); } public function users() { return $this->belongsToMany(User::class); } public static function deleteAndDetach($item) { //Detach users from this item foreach ($item->users as $user) { User::findOrFail($user->id)->items()->detach($item->id); } //Delete item $item->delete(); } /** * Return the items from logged in user * * @return \App\Item */ public static function fromAuthUser() { return (new static)->where('user_id', \Auth::id()); } /** * Return a specified item * * @return void */ public function returnItem() { $this->used_by = null; $this->waiting_user_id = null; $this->save(); } }