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