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