For example, I have a Product, and I have BaseProduct.
In the model for the product, I indicated the following:
public function BaseProduct()
{
return $this->belongsTo("BaseProduct", "BaseProductId");
}
In BaseProduct, I indicated the following relationship:
public function Products()
{
return $this->hasMany("Product", "ProductId");
}
If I wanted to select a product, for example:
$Product::first()
I can get BaseProduct by doing the following:
$Product::first()->BaseProduct()->get();
Instead of getting an array of the result from this, how can I get Modelfor BaseProduct, so that I can get all the children of BaseProduct, which means all products that have a foreign key related to this BaseProduct.
I tried BaseProduct()->all();instead, but this is not a valid method.
Edit:
I created the following chain of function calls - but this is terrible.
return BaseProduct::find(Product::first()->BaseProduct()->getResults()['BaseProductId'])->Products()->getResults();
Final editing:
BaseProduct. Products() return $this->hasMany("Product", "ProductId");, ProductId BaseProductId.
, , :
Product::first()->BaseProduct->products;
.