首頁  >  問答  >  主體

找不到列:1054未知列'tbl_destinations.id'在'where子句'中的PDOException:SQLSTATE:在/var/www/html/...Connection.php:338中重寫為:找不到列:1054未知列'tbl_destinations.id'在'where子句'中的資料庫異常

我的資料庫中的 id 欄位是 des_id ,如何將其變更為 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
    ]);
});

P粉677573079P粉677573079335 天前480

全部回覆(1)我來回復

  • P粉458725040

    P粉4587250402023-12-13 16:28:53

    你的程式碼對我來說看起來不錯。

    嘗試在您的目標模型中進行設定:

    protected $primaryKey = 'des_id';

    回覆
    0
  • 取消回覆