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