I'm really confused why I keep getting a null value when retrieving data from my data model.
Here's my model:
class Supplier extends Eloquent {
public function purchase_orders()
{
return $this->hasMany('Purchase_order','supplier_id');
}
}
And my controller:
$purchase_orders = Supplier::find(1)->purchase_orders;
dd($purchase_orders);
This results to NULL.
My Purchase_order table's fields are:
('id','supplier_id','name','status','date')
And my Suppliers table's fields are:
('id','name','email', 'address')
By the help of @hayhorse I discovered that the one causing the issue was the underscore on the name of the class, to solve the issue i just renamed my class from purchase_orders
to purchaseOrder
and by that i can now user the proper syntax which is:
$purchase_orders = Supplier::find(1)->purchase_orders;
again credits to @hayhorse