The Profile model with (id | user_id | name) columns has user relation as:
public function user(){
return $this->belongsTo(User::class);
}
the User model has skills relation as:
public function skills()
{
return $this->belongsToMany(Skill::class);
}
the pivot table is skill_user with user_id | skill_id columns and Skill model user relation as:
public function users(){
return $this->belongsToMany(User::class);
}
How I can search for profiles that have a specific skill from the search request.
$profiles = Profile::with('users')->where('name', 'like', ''.$term.'%')->get();
but I get an error of not profile_skill table!
I can reach to each profile that has a specific skill through
$profile->user->skills
but how I can reach to these skills from :
<input name="term" type="text" />
I have tested users relation in Profile model but I get error :
public function users(){
return $this->hasManyThrough(User::class, Skill::class, 'skill_id', 'user_id');
}