I’ve this simple application built with Laravel and Eloquent, that should connect to a localhost phpmyAdmin Database.
I’ve got this method:
public function clickOrderPlateClient($id_client, $id_plate){
$order = Order::where('id_client', $id_client)
->where('id_plate', $id_plate)
->first();
$order->qt = ($order->qt) + 1;
$order->save();
}
which should increment by 1 the attribute “qt” in my table “orders” (described by the class Order
) in the record corresponding to the given client which has ordered the given dish.
But I’m always getting an “Illegal offset type” error corresponding to the $order->save();
row.
error
this is my Order
class:
<?php
namespace AppModels;
use IlluminateDatabaseEloquentFactoriesHasFactory;
use IlluminateDatabaseEloquentModel;
class Order extends Model
{
protected $table ='orders';
protected $primaryKey = ['id_client','id_plate'];
public $timestamps = false;
public $incrementing = false;
public function getClient(){
return $this->belongsTo('AppModelsClient','id_client');
}
public function getPlate(){
return $this->belongsTo('AppModelsPlates','id_plate');
}
}