Tables
Business
id
name
Portfolio
id
image
description
business_id
Models
class Business extends \Eloquent
{
public function portfolio()
{
return $this->hasMany('Portfolio');
}
}
class Portfolio extends \Eloquent {
public function business()
{
return $this->belongsTo('Business');
}
}
Now i want to know is it possible if i have a portfolio id then get all the portfolios which belongs the same business id.
Since you have the portfolio id, you first find the portfolio, then you get the business for that portfolio, and then you get all the portfolios for that business:
$portfolio = Portfolio::find($id);
$business = $portfolio->business;
$portfolios = $business->portfolio;
Or, with a one liner:
$portfolios = Portfolio::find($id)->business->portfolio;