'SQLSTATE[42S22]:Column not found:1054 Unknown column'tabl_name.id' in'where clause'select*from`tabl_name`where'tabl_name`.`id`=16

my id field in a database named des_id is there a specific way to change from table_name.id to table_name.des_id?

Route::post('Specific/uri', function (Request $request) {
    $request->validate([
        'destination_id' => 'required|exists:Database Name.Table Name,des_id',
        'from' => 'required|numeric|min:0',
        'to' => 'required|numeric|min:0',
    ]);
    $destination_id = Destination::findOrFail($request->destination_id);
    $from = $request->from;
    $to = $request->to;
    dispatch(new testJob($destination_id, $from, $to));
    return response()->json([
        'status' => true
    ]);
});


Solution 1:[1]

You won't be able to use the find or findOrFail if you don't use the standard naming convention for the identifier as laravel expects which is id. findOrFail expects the primary key to be named "id".

Because your primary key is named "des_id", for you to have the same exception behavior, you should use the where clause then end it with the firstOrFail() method which will offer a similar behavior to findOrFail.

You can learn more about findOrFail and firstOrFail here.

This is how you should perform that call to have the same Not Found Exception handling as findOrFail.

$destination_id = Destination::where('des_id','=',$request->destination_id)->firstOrFail();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dom DaFonte