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