lundi 27 juin 2016

How to query in laravel

I have User Model. In user Model I have three user type Admin,Trainer,Student. I have Job Model, I am storing the the id of trainer ,student and job in pivot table such that one trainer is assigned against one job and many students. Now after storing the ids as foreign key in pivot table.

Now how i can show in a view all trainer, job and assigned students. In la-ravel 5.2

User Model

 public function Job_User()
    {
        return $this->belongsToMany('App\HTTP\Models\Job', 'jobs_users', 'user_id', 'job_id')->with-pivot('job_id');}

 public function Trainer_User()
    {
        return $this->belongsToMany('App\HTTP\Models\Job', 'jobs_users', 'user_id', 'trainer_id')->with-pivot('trainer_id');

    }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire