Hi guys,
I'm trying to use something like my implementation of hasManyThrough query, could you please tell me if, that's what I'm doing is bad practice or not? I'm kinda new to Laravel.
I'm trying to get All keywords for current company, through keywords_plans.
Company ( has_many keywords_plans ) KeywordsPlan ( belongs_to company and belongs_to_many keywords ) Keyword ( belongs_to_many keywords plans)
I have pivot table for connecting keywords with keywords_plans. Keywords_plans uses "company_id" column for referencing company.
keywords_plans company_id
keyword_keywords_plans keyword_id keywords_plan_id
And this is how I made it.
$keywords = $company->keywords();
Company.php
public function keywords()
{
$keywords = Keyword::whereHas('keywords_plan', function($q)
{
$q->where('company_id', '=', $this->id);
})->get();
return $keywords;
}
is this bad practise or not? I would say I'm using too many request.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community