I have my dropdown with options populated from the database. Along with I have an option named other
with value -1
Below is the html output for better understanding
The Other is hardcoded
.
I have created a request validation file and code as below.
<code> <?php
namespace AppHttpRequestsProfilesForm;
use IlluminateFoundationHttpFormRequest;
class BasicRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, IlluminateContractsValidationValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'name' => 'required|min:3|max:30',
'relation' => 'required'
];
}
}
</code>
<code> <?php
namespace AppHttpRequestsProfilesForm;
use IlluminateFoundationHttpFormRequest;
class BasicRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, IlluminateContractsValidationValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'name' => 'required|min:3|max:30',
'relation' => 'required'
];
}
}
</code>
<?php
namespace AppHttpRequestsProfilesForm;
use IlluminateFoundationHttpFormRequest;
class BasicRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, IlluminateContractsValidationValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'name' => 'required|min:3|max:30',
'relation' => 'required'
];
}
}
Now, how do I write a validation condition to check only for options that are not equal to -1 are available in the database.
Lets say if I use exists:relations,name
works fine for myself…nephew but will throw error for -1. I don’t want to add other into the db table.