Hi ,
First, let's examine the table structure:
estimate
id - integer
order_id - integer
description - string
orders
id - integer
estimate_id - integer
amount - int
customers
id - integer
firstname - string
lastname - string
Models :
class Estimate extends Model
{
protected $table = 'estimate';
public function order()
{
return $this->belongsTo('App\Models\Order','order_id');
}
}
Order
class Order extends Model
{
protected $table = 'order' ;
public function customer()
{
return $this->belongsTo('App\Models\Customer', 'customer_id');
}
}
Client
class Customer extends Model
{
protected $table = 'customer' ;
}
when i tried :
public function index()
{
return response()
->json([
'model' => Estimate::with('order','customer')->paginate(15)
]);
}
I get a error :
Illuminate\Database\QueryException
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'customer.estimate_id' in 'field list
how to fix with it with Eloquent in the cleanest way ?
Thank you in advance