This my Input field:
<div class="col-md-4 form-group">
<label class="form-label fw-bold text-muted" >Em Code</label>
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text">xyz.</div>
</div>
<input class="form-control" name="em_code" type="number" value="{{ old('em_code') }}">
@error('em_code')
<span class="text-danger">{{ $message }}</span>
@enderror
</div>
</div>
And as expected in my controller in returns only the number that's passed on.
public function store(Request $request)
{
dd($request->em_code);
}
Now I want it to return me the value as xyz.####
Of course I can concatenate it in my controller using the following -
'em_code' => 'bZm.'.$request->em_code,
But I want it concatenated from the blade input file,because I'm going to validate it as Unique. But in my database it is stored as bZm.1111. So in case of a input of 1111 the validation rule will not pass any exception. However, mySql will return an error because this column marked unique there.
So, in order to get an proper check for unique em_code I'm trying to get it concatenated from the input and pass it as that to the controller.
You're welcome to give some other solution for this problem.
Thanks!
In a form request class, you can prepare for validation.
https://laravel.com/docs/9.x/validation#preparing-input-for-validation
protected function prepareForValidation()
{
$this->merge([
'em_code' => 'bZm.' . $this->em_code,
]);
}