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