mirror of
				https://github.com/pelican-dev/panel.git
				synced 2025-10-31 21:46:51 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			59 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			59 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace App\Http\Requests\Admin;
 | |
| 
 | |
| use App\Models\Server;
 | |
| use Illuminate\Validation\Rule;
 | |
| use Illuminate\Validation\Validator;
 | |
| 
 | |
| class ServerFormRequest extends AdminFormRequest
 | |
| {
 | |
|     /**
 | |
|      * Rules to be applied to this request.
 | |
|      */
 | |
|     public function rules(): array
 | |
|     {
 | |
|         $rules = Server::getRules();
 | |
|         $rules['description'][] = 'nullable';
 | |
|         $rules['custom_image'] = 'sometimes|nullable|string';
 | |
| 
 | |
|         return $rules;
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * Run validation after the rules above have been applied.
 | |
|      */
 | |
|     public function withValidator(Validator $validator): void
 | |
|     {
 | |
|         $validator->after(function ($validator) {
 | |
|             $validator->sometimes('node_id', 'required|numeric|bail|exists:nodes,id', function ($input) {
 | |
|                 return !$input->auto_deploy;
 | |
|             });
 | |
| 
 | |
|             $validator->sometimes('allocation_id', [
 | |
|                 'required',
 | |
|                 'numeric',
 | |
|                 'bail',
 | |
|                 Rule::exists('allocations', 'id')->where(function ($query) {
 | |
|                     $query->where('node_id', $this->input('node_id'));
 | |
|                     $query->whereNull('server_id');
 | |
|                 }),
 | |
|             ], function ($input) {
 | |
|                 return !$input->auto_deploy;
 | |
|             });
 | |
| 
 | |
|             $validator->sometimes('allocation_additional.*', [
 | |
|                 'sometimes',
 | |
|                 'required',
 | |
|                 'numeric',
 | |
|                 Rule::exists('allocations', 'id')->where(function ($query) {
 | |
|                     $query->where('node_id', $this->input('node_id'));
 | |
|                     $query->whereNull('server_id');
 | |
|                 }),
 | |
|             ], function ($input) {
 | |
|                 return !$input->auto_deploy;
 | |
|             });
 | |
|         });
 | |
|     }
 | |
| }
 | 
