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