jeudi 11 février 2021

Getting data from checkbox into laravel controller

This seems so simple. But has me stumped... I have a table with some records and one cell has a bootstrap custom-switch input in it. The switches are rendering correctly. But i cannot get the array back into my controller.

Blade View

<form action="" method="POST">
    @csrf
    @method('PUT')
    <div class="custom-control custom-switch">
        <input  type="checkbox" 
                class="custom-control-input" 
                id="sitelive" 
                name="sitelive[]" 
                value="" 
                onchange="javascript:this.form.submit()" 
                @if($prop->sitelive == 1) checked @endif>
        <label class="custom-control-label" for="sitelive"></label>
    </div>
</form>

Controller

class AdminLiveOnSiteController extends Controller
{    
    public function update(Request $request, $id)
    {
        $prop = Properties::findorFail($id);    
        $validated = $request->validate(['sitelive' => 'required']);
        $prop->sitelive = $validated['sitelive'];        
        $prop->save();

        $request->session()->flash('alert-class', 'alert-success');
        $request->session()->flash('message', 'Live status updated!');

        return redirect()->route('Admin.Admin',  [ 'Property', 'All' ]);            
    }
}

Any ideas?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3rBZoBY
via IFTTT

Aucun commentaire:

Enregistrer un commentaire