Ad

Laravel Eloquent Update, 500 Internal Server Error

- 1 answer

I want to update my database with Laravel eloquent update, but response is always 500

This is my model

class Tunggakan extends Model
{
protected $table = 'kredit_tunggakan';
/**
 * @var array
 */
}

This is the function

public function statusTunggakan(){

    $status = Tunggakan::find(2);
    $status -> id_status = 77;
    $status -> save();
}

This is the route

Route::prefix('tunggakan')->group(function () {
Route::post('/statusTunggakan','[email protected]');
});

Exception:

[2022-03-24 11:20:14] production.ERROR: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'kredit_tunggakan.updated_at' in 'field list' (SQL: update kredit_tunggakan set id_status = 77, kredit_tunggakan.updated_at = 2022-03-24 11:20:14 where id = 2) {"exception":"[object] (Illuminate\\Database\\QueryException(code: 42S22): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'kredit_tunggakan.updated_at' in 'field list' (SQL: update kredit_tunggakan set id_status = 77, kredit_tunggakan.updated_at = 2022-03-24 11:20:14 where id = 2) 

Thanks before, for helping..

Ad

Answer

Loking at the exception:

Column not found: 1054 Unknown column 'kredit_tunggakan.updated_at

Seems like you don't have updated_at column in your database table. There are two solutions for this:

I: Create/update your migration to include timestamp fields:

 $table->timestamps();

II: Set timestamps to false when updating the record:

$status = Tunggakan::find(2);
$status->timestamps = false;
$status -> id_status = 77;
$status -> save();
Ad
source: stackoverflow.com
Ad