0

I am going round in circles trying to update data to the database, I finally have got rid of all the errors so now its correctly redirects with no error yet it isnt updating on the site or on the database.

Any help would be greatly appreciated, thanks!

web.php

Route::put('/my-saved-routes/{myroute_id}', 'MyroutesController@update');

MyroutesController.php

public function update(Request $request, $id)
{    
     $Myroutes = Myroutes::find($id);
     $Myroutes->start = $request->input('start');
     $Myroutes->end = $request->input('end');
     $Myroutes->waypoints = $request->input('waypoints');

     $Myroutes->save();

     return redirect('/my-saved-routes');
}

show.blade.php

<div class="col-md-4">
                            <h2>Route {{ $myroute->myroute_id }}</h2>                               
                            <form method="put" action="/my-saved-routes">
                                {{ method_field('put') }}
                                {{ csrf_field() }}
                                <input type="hidden" name="_method" value="PUT" />
                                <div class="form-group">
                                    <label>Start Point</label>
                                    <input type="text" id="start" name="start" class="form-control" value="{{ $myroute->start }}" required/>
                                </div>

                                <div class="form-group">
                                    <label>End Point</label>
                                    <input type="text" id="end" name="end" class="form-control" value="{{ $myroute->end }}" required/>
                                </div>

                                <div>
                                <label for="mode">Mode of Travel</label>
                                    <select id="mode" class="form-control" onchange="calculateAndDisplayRoute();">
                                      <option value="DRIVING" name="driving">Driving</option>
                                      <option value="WALKING" name="walking">Walking</option>
                                      <option value="BICYCLING" name="cycling">Cycling</option>
                                      <option value="TRANSIT" name="public-transport">Public Transport</option>
                                    </select>
                                </div>

                                <p>Note: Public Transport is only available for start and end points.</p>


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

                                <input type="button" class="btn btn-secondary" value="+" onClick="addInput('dynamicInput');" style="padding:0 10px;">               
                                </br></br>
                                <input type="button" id="calc-route" style="color:#2b2b2b" class="btn btn-light" value="Calculate Route"/>

                                <input type="submit" id="update-route" class="btn btn-success" value="Update"/>
                                <input type="button" class="btn btn-danger" value="Delete"/>

                            </form> <!-- end of form -->    

Myroutes.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

use Illuminate\Http\Request;

class Myroutes extends Model
{
    protected $fillable = [
        'myroute_id',
        'user_id',
        'start',
        'end',
        'waypoints'
    ];

    protected $primaryKey = 'myroute_id';

}
1

3 Answers 3

3

You can do like below

Myroutes::where('id', $id)
                ->update(['start' => $request->input('start'),
                         'end'=>$request->input('end'),
                         'waypoint'=>$request->input('waypoints')]
                        );
Sign up to request clarification or add additional context in comments.

2 Comments

Error message SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'waypoints' cannot be null (SQL: update myroutes set start = deee, end = d, waypoints = , updated_at = 2018-04-27 10:13:23 where myroute_id = 26) How to change waypoints to allow it to save as null
That's a database schema issue. You need to create a migration that changes 'waypoints' to have the ->nullable() method passed to it.
0

try to

<form method="put" action="/my-saved-routes">

update

<form method="post" action="/my-saved-routes/{{ $myroute->myroute_id }}">

Comments

0

Try the following:

<form class="form" method="post" action="/my-saved-routes/{{ $$myroute->myroute_id) }}">
  {{ method_field('patch') }}
  {{ csrf_field() }}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.