mardi 5 novembre 2019

Laravel Custom attributes affecting data insertion to db

I have created custom attributes so that I can directly access them in my blade file and it works well, but during my testing in my db, it is the one that gives the QLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'field list' error. Here's what I've done in inserting the custom attributes in my model:

protected $fillable = [
    'room_name',
    'room_code',
];

protected $dates = [
    'created_at',
    'updated_at'
];

protected $attributes = ['room_total_booking', 'room_complete_booking'];

public function getRoomTotalBookingAttribute($id){
    return \App\Models\Guest\BookingDetail::where('room_list_id', $id)->count();
}

public function getRoomCompleteBookingAttribute($id){
    return \App\Models\Guest\BookingDetail::where('room_list_id', $id)->whereReservationStatus(1)->count();
}

But when I comment out the attributes, it works well. Here is the full error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'field list' (SQL: insert into room_lists (0, 1, room_name, room_code, updated_at, created_at) values (room_total_booking, room_complete_booking, Test2, Test101, 2019-11-05 11:00:16, 2019-11-05 11:00:16))

If you can see it, my declared custom attributes are in the value fields. Can someone help me figure this out?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire