mardi 2 mai 2017

Laravel Flash errors - How to check if a checkbox is checked?

I'm trying to do flash messages in Laravel, now the flash messages work for success messages and error messages on pages that don't have checkboxes.

I have a view called 'deleteappointmentform' which requires the user to check a checkbox and it deletes the checked appointments, however if I don't check any checkbox and click submit it gives me a success message without actually checking if they've checked and checkboxes. I'm trying to get it to display an error message if they don't check any checkboxes

Any help's appreciated, thanks

This is the function that deals with deleting appointments

function deleteAppointment(Request $request)
{
    Appointment::destroy($request->appointments);
    Session::flash('successCancelAppointment', 'Appointment cancelled successfully!');
return redirect('all');
}

This is my messages blade

@if (Session::has('successCancelAppointment'))

<div class="alert alert-success" role="alert">
    <strong>Success: </strong> 
</div>
    @endif



@if (count($errors) > 0)

<div class="alert alert-danger" role="alert">
    <strong>Errors:</strong>
    <ul> 
    @foreach ($errors->all() as $error)
        <li></li>
        @endforeach

    </ul>
</div>
@endif

This is my deleteappointmentsblade

@extends('layouts.master')
@section('title', 'Cancel Appointment')
@section('content')

<form action="" method="POST">
    
     @foreach ($appointments as $appointment)
        <div>
            <label>  </label>
            <label>Has an appointment at: </label>
            <label>On: </label>
            <label>With Dr: </label>

            <input type='checkbox' value='' name='appointments[]'/>
        </div>
    @endforeach
    <input type="submit" name="submitBtn" value="Cancel Appointments">
</form>


@endsection



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire