vendredi 27 avril 2018

Allow the option for data to be submitted to database as null Laravel - Error SQLSTATE[23000]

I am receiving the error 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:53:25 where myroute_id = 26) as I am updating the data to the database and have left the waypoints field blank.

I want this field to be allowed to be left blank and saved, or if any input is added it updates to the database.

I haven't set the input field as required nor included the waypoints field in my validate request function in the controller. The waypoints column in the database is VARCHAR.

MyroutesController.php

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');
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire