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