There are space comes after every character of field name while displaying errors in blade template in laravel 9 as mentioned in uploaded image
CODE IN HTML IS :
<form action="{{route('saveAsset')}}" method="post">
{{@csrf_field()}}
<div class="form-group">
<label for="assetTitle" class="mt-2 mb-2">{{$assetCategory->category}} TITLE :</label>
<input type="text" class="form-control" name="assetTitle" id="assetTitle" placeholder="Enter Asset Title">
</div>
<div class="inputError">@error('assetTitle') Error: {{ $message }} @enderror </div>
<input type="hidden" name="assetCateId" id="assetCateId" value="{{$assetCategory->id}}">
@if(count($attributes) > 0)
@foreach($attributes as $attribute)
<label for="assetType-{{$attribute->attr_id}}" class="mt-4 mb-2">{{$attribute->attr_title}} : </label>
<div class="form-group">
<select class="form-select" name="{{$attribute->attr_title}}" id="attribute-{{$attribute->attr_id}}" aria-label="Default select example">
<option value="">Select {{$attribute->attr_title}}</option>
@foreach($attrValues as $attrValue)
@if ($attrValue->attr_id == $attribute->attr_id && strlen($attrValue->value) > 0 )
<option value="{{$attribute->attr_id}}-{{$attrValue->value_id}}" > {{$attrValue->value}}</option>
@endif
@endforeach
</select>
</div>
<div class="inputError"> @error("{$attribute->attr_title}") Error: {{ $message }} @enderror </div>
@endforeach
@endif
<div>
<button type="submit" class="btn btn-primary mt-3 px-4">Save</button>
</div>
</form>
CODE IN CONTROLLER IS :
$fields = $req->input();
$ValidationRules=[];
foreach($fields as $fieldName=>$fieldvalue){
if($fieldName == "assetTitle"){
$ValidationRules[$fieldName] = 'required|unique:assets,title';
}else{
$ValidationRules[$fieldName] = 'required';
}
}
$req->validate($ValidationRules);
2
Answers
I guess you have made some changes in
resources/lang/en/validation.php
file.in this or any language you have set , there is a attribute named
attributes
that you can change the the attribute name displaying in error message.
because the error message of
asset
field is ok I do not think it’s a general error . check this file andattributes
ormessages
key in it.Don’t know if you still need help but I just had the same issue and I think it’s because you might have the input names with text uppercase, laravel automaticly adds a space for each uppercase character in the name attribute when showing the errors.
For example:
name="thisModel"
Will display as:
… this Model …
If you have:
name="MODEL"
Will display as:
… M O D E L …
Hope this helps someone in the future x)