vendredi 27 avril 2018

Saving array to database to output it again Laravel

So currently my array is being converted to a string to save to the database. But this means when i get the data from the database the string is filling one input field when it should fill separate input fields, which im thinking would have been more possible if it was still an array.

controller

 public function store(Request $request)
{   
    $this->validate(request(), [
        'start' => 'required',
        'end' => 'required'
    ]);

    if (Auth::check()) {

        Myroutes::create([ //posting to myroutes table
            'user_id' => Auth::user()->id,
            'start' => $request->start,
            'end' => $request->end,
            'waypoints' => implode(",", $request->waypoints)
        ]);
        return redirect('/my-saved-routes');
    } else {
        return redirect('/login');
    }
}
 public function update(Request $request, $id)
{    
     Myroutes::where('myroute_id', $id)
    ->update(['start' => $request->input('start'),
             'end'=>$request->input('end'),
             'waypoints'=>$request->input('waypoints')]
            );
     return redirect('/my-saved-routes');
}

The data is being input and saved to database from here - showing.blade

<div id="dynamicInput" class="form-group">
                    <label>Additional Destinations</label>
                    <input type="text" name="waypoints[]" class="form-control" autocomplete="on">
                </div>

                <input type="button" class="btn btn-secondary" value="+" onClick="addInput('dynamicInput');" style="padding:0 10px;">               

And shown from the database to here - edit.blade

<div id="dynamicInput" class="form-group">
                                    <label>Additional Destinations</label>
                                    <input type="text" name="waypoints" class="form-control" autocomplete="on" value="">
                                </div>

But it outputs like so string-output



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

Aucun commentaire:

Enregistrer un commentaire