Проверка модального блейда не отображается - PullRequest
0 голосов
/ 15 мая 2019

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

enter image description here

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">&times;</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();

Ответы [ 3 ]

0 голосов
/ 15 мая 2019

Вам нужен класс Validator в вашем контроллере use Validator; Попробуйте то же самое, как это

     $rules = array (
         'motivo_baja'  => 'required'       );
 $error = Validator::make($request->all(), $rules;
 if ($error->fails())
{
     return response()->json(['errors' => $error->errors()->all()]);
 }
0 голосов
/ 15 мая 2019

Просто добавьте required и autofocus к <textarea>

0 голосов
/ 15 мая 2019

Недопустимая обратная связь класса CSS имеет значение по умолчанию display: нет в начальной загрузке css, добавьте d-блок класса (при условии начальной загрузки 4) или другой класс, чтобы переопределить это значение css и установить display в block:

@if ($errors->has('motivo_baja'))
    <span class="invalid-feedback d-block" role="alert">
         <strong>{{ $errors->first('motivo_baja') }}</strong>
    </span>
@endif
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...