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