action = $action; $this->request = $request; $this->model = $menu; $this->function = Str::camel($action); $this->executeAction(); return $this->model; } public function store(Menu $menu, array $request) { $attributes = $request; $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $menu = $menu->create($attributes); return $menu; } public function update(Menu $menu, array $request) { $attributes = $request; $menu->update($attributes); return $menu; } public function destroy(Menu $menu, array $request) { $menu->delete(); return $menu; } public function copy(Menu $menu, array $request) { $count = $request['count'] ?: 1; if ($count == 1) { $menu = $menu->replicate(); $menu->created_at = Carbon::now(); $menu->save(); return $menu; } for ($i = 1; $i <= $count; $i++) { $new = $menu->replicate(); $new->created_at = Carbon::now(); $new->save(); } return $menu; } }