Skip to content
Advertisement

Laravel eloquent update, 500 Internal Server Error

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','TunggakanControl@statusTunggakan');
});

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..

Advertisement

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();
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement