Home > Mobile >  PDOException:SQLSTATE[42S22]:Column not found: 1054 Unknown column 'tbl_destinations.id' i
PDOException:SQLSTATE[42S22]:Column not found: 1054 Unknown column 'tbl_destinations.id' i

Time:04-18

my id field in my database is des_id , how can i change it to des_id?

Route::post('Itest/LoadSuppliers', function (Request $request) {
    $request->validate([
        'destination_id' => 'required|exists:mysql.tbl_destinations,des_id',
        'from' => 'required|numeric|min:0',
        'to' => 'required|numeric|min:0',
    ]);
    $destination_id = Destination::where('des_id','=', $request->destination_id)->firstOrFail();
    $from = $request->from;
    $to = $request->to;
    dispatch(new TestJob($destination_id, $from, $to));
    return response()->json([
        'status' => true
    ]);
});

CodePudding user response:

Your code looks good to me.

Try setting this in your Destination Model:

protected $primaryKey = 'des_id';
  • Related