mardi 9 octobre 2018

Error retrieving a checked Checkbox in Laravel as a boolean

Am a bit new to Laravel and am working on a Larvel Application which has a checkbox field which should have a boolean value of 1 when the user checks the checkbox and zero when the checkbox is unchecked. I want to retieve the boolean value as either 1 or 0 and save in a db.. Please assist?

View

<form method="POST" action="" id="travel_form"  accept-charset="UTF-8">

    <input type="hidden" name="_token" value="">
    <div class="check-now ">
        <h1 class="cover-travel">I am travelling with</h1>
        <label class="spouse-me">
            <h1 class="pumba">Spouse</h1>
            <input id="spouse" type="checkbox" name="spouse">
            <span class="checkmark" name="spouse"></span>
        </label>
        @if ($errors->has('spouse'))
            <span class="help-block">
                <strong></strong>
            </span>
        @endif
    </div>

    <button type="submit" class="form-b3c"> Get Plans</button>
</form>

Controller

 public
    function validatePlanEntries(Request $request)
    {

        $validation = $this->validate($request, [
            'WithSpouse' => (\Input::has('spouse')) ? 1 : 0;
        ]
}




Aucun commentaire:

Enregistrer un commentaire