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); }); }); } }