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