Path: blob/1.0-develop/app/Http/Requests/Admin/ServerFormRequest.php
10266 views
<?php12namespace Pterodactyl\Http\Requests\Admin;34use Pterodactyl\Models\Server;5use Illuminate\Validation\Rule;6use Illuminate\Validation\Validator;78class ServerFormRequest extends AdminFormRequest9{10/**11* Rules to be applied to this request.12*/13public function rules(): array14{15$rules = Server::getRules();16$rules['description'][] = 'nullable';17$rules['custom_image'] = 'sometimes|nullable|string';1819return $rules;20}2122/**23* Run validation after the rules above have been applied.24*/25public function withValidator(Validator $validator): void26{27$validator->after(function ($validator) {28$validator->sometimes('node_id', 'required|numeric|bail|exists:nodes,id', function ($input) {29return !$input->auto_deploy;30});3132$validator->sometimes('allocation_id', [33'required',34'numeric',35'bail',36Rule::exists('allocations', 'id')->where(function ($query) {37$query->where('node_id', $this->input('node_id'));38$query->whereNull('server_id');39}),40], function ($input) {41return !$input->auto_deploy;42});4344$validator->sometimes('allocation_additional.*', [45'sometimes',46'required',47'numeric',48Rule::exists('allocations', 'id')->where(function ($query) {49$query->where('node_id', $this->input('node_id'));50$query->whereNull('server_id');51}),52], function ($input) {53return !$input->auto_deploy;54});55});56}57}585960