Merhabalar bir konu hakkında yardımınızı istiyecektim.Modalda error mesaj göstermeye çalışıyorum ama rule olmasına rağmen orayı boş geçiyor.
İndex.blade.php
<script>
function DefineNewColor() {
$('#pop_modal').modal('show');
$('#pop_modal_head_text').html('<i class="fas fa-cubes"></i> Define New Color!');
$('#pop_body').hide();
$('#pop_define_new_material_body').show();
$('#define_color').focus();
}
$(function () {
$('#pop_define_new_material_body').on('submit', function (e) {
e.preventDefault();
$.ajax({
url: "{{ route('submember.color-categories.store') }}",
method: 'POST',
data: new FormData(this),
cache: false,
contentType: false,
processData: false,
success: function (data) {
window.location.reload()
},
error: function (err) {
if (err.status !== 422) {
return
}
$('#define_form_errors')
.removeClass('hidden')
.append(
Object.values(err.responseJSON.errors).map(function (error) {
return '<li>' + error[0] + '</li>';
})
)
}
});
})
})
</script>
{{ $dataTable->scripts() }}
<div id="pop_modal" class="modal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 id="pop_modal_head_text" class="modal-title">
'<i class="fas fa-exclamation-triangle text-warning"></i> Attention!
</h5>
<button
type="button"
class="close"
data-dismiss="modal"
aria-label="Close"
>
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div id="pop_body"></div>
<ul id="define_form_errors" class="alert alert-danger hidden"></ul>
<form id="pop_define_new_material_body" style="display: none" action="{{ route('submember.color-categories.store') }}" method="post" enctype="multipart/form-data">
@csrf
<div class="col mb-2 text-left">
<input
class="form-control"
type="text"
id="define_color"
name="color"
placeholder="* TYPE COLOR"
required
/>
</div>
<div class="col mb-2 text-left">
<input
class="form-control"
type="text"
id="define_pantone"
name="pantone"
placeholder="* TYPE PANTONE"
required
/>
</div>
<div class="col mb-2 text-left">
<textarea name="description" cols="30" rows="10" class="form-control" placeholder="Description"></textarea>
</div>
<div class="col mb-2 text-left">
<input
class="form-control"
type="text"
id="define_color_group"
name="color_group"
placeholder="* TYPE COLOR GROUP"
required
/>
</div>
<div class="col mb-2 text-left">
<div class="input-group mb-3">
<div class="custom-file">
<input
type="file"
class="custom-file-input"
id="inputGroupFile02"
multiple
name="image[]"
/>
<label class="custom-file-label" for="inputGroupFile02">Choose Image</label>
</div>
</div>
</div>
<div class="col mb-2 text-left">
<button
class="btn btn-warning"
type="submit"
id="define_colors_submit"
>
<i class="far fa-save"></i> SAVE COLOR GROUP
</button>
</div>
</form>
</div>
</div>
</div>
</div>
@endpush
Rule dosyam
public function rules()
{
return [
'color' => ['required', 'string', 'max:191'],
'pantone' => ['required', 'string', 'max:191'],
'color_group' => ['required', 'string', 'max:191'],
'image.*' => ['required','image'],
];
}
Controller dosyam
public function store(StoreColorCategoryRequest $request)
{
$color = ColorCategory::create($request->only('color', 'pantone', 'color_group','description'));
foreach ($request->file('image') as $file) {
$color->upload($file);
}
return response()->json([
'status' => true,
'data' => array_merge($color->toArray(), [
'photo' => $color->photo?->url(),
])
]);
}
Aldığım hata ise object null foreach resmi boş geçtiğimde modalda erroru göstermiyor.