jeudi 29 octobre 2015

Laravel return relationship object with data from pivot table

I have the following tables setup in my application:

  • user
  • job_title
  • job_title_user (pivot table)

I have setup a relationship model for job titles in the user model, like so:

/**
 * The job titles that belong to the user.
 *
 * @return Object
 */
public function jobTitles()
{
    return $this->belongsToMany('App\Models\User\JobTitle');
}

I want to be able to select multiple rows from the user table, whilst joining on the job_title_id field from the job_title_user table.

So basically i'm looking to do a select on the user table, but also select which job titles the user has assigned to them.

How can I achieve this?

Thanks!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire