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