Я обновляю столбец модальной блочной формой, и я немного запутался в проверке:

modal.blade.php
<div class="modal fade" id="baja_{{$id}}" tabindex="-1" role="dialog" aria-labelledby="bajaModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel" style="color: black;">Dar de Baja a {{$id}} </h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form method="POST" action="{{ route('contratos.baja', $id) }}">
@csrf @method('PATCH')
<div class="form-group">
<label for="motivo_baja" class="col-form-label" style="color: black; "><strong>Motivo:</strong></label>
<textarea class="form-control" id="motivo_baja" name="motivo_baja" style="width:100%; height: 150px;"></textarea>
@if ($errors->has('motivo_baja'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('motivo_baja') }}</strong>
</span>
@endif
</div>
<div class="form-group row">
<button id="cerrar" type="button" class="btn btn-primary mx-auto" data-dismiss="modal">Cerrar</button>
<button id="dar_baja" type="submit" class="btn btn-primary mx-auto">Dar de Baja</button>
</div>
</form>
</div>
</div>
</div>
Я ожидаю, что подтвердит , когда textarea
пусто, я проверил, и это так, но непоказывает сообщение проверки в этой части:
@if ($errors->has('motivo_baja'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('motivo_baja') }}</strong>
</span>
@endif
Проблема:
Кажется, что переменная errors
не получает ошибки.Но, как я сказал, когда я ничего не пишу в текстовое поле и не отправляю данные, таблица не обновляется, поэтому что-то происходит, потому что проверка работает, но я не знаю, как с этим справиться.Как я могу обработать эти ошибки, чтобы показать их в модальном, а не просто закрыть его, не давая никакого сообщения?
Мой контроллер ContratoController.php
public function baja(Request $request, $contrato_id){
$request->validate([
'motivo_baja' => 'required|max:300',
]);
$contrato = Contrato::find($contrato_id);
$contrato->motivo_baja = $request->get('motivo_baja');
$contrato->save();
return redirect()->route('contratos.index', $contrato->legajo_id)->with('success', 'Ok!');
}
Мне нужносделать этот столбец nullable
таким же, как в миграции :
$table->string('motivo_baja')->nullable();