Home LARAVEL ELOQUENT - I want to add column from user table to a relation table
Reply: 0

LARAVEL ELOQUENT - I want to add column from user table to a relation table

user6333
1#
user6333 Published in September 19, 2018, 9:27 am

I am not much familiar with eloquent orm in laravel

I have 3 tables they are

 -- leads
       |
        Lead_appointments

   and users table

since lead_appointments belongs to leads references id on leads by lead_id

the leads_appointments has a column called created_by with user's id in it

I am trying to query user's name and email along with the result as another column when query using eloquent

Lead Model

  class Leads extends Model
     { 
        public function appointments()
        {
           return $this->hasMany('App\Models\LeadsAppointments', 'lead_id');
        }
     }

My eloquent query in controller

   return $this->lead->with('appointments')->find($id);

the result is like this

In under appointments i also want user email and name along with created by in it

But I couldn't figure it out

share|improve this question
  • "leads_appointments has a column called created_by with user's id" so you have User Model ok? and do you have any relation between User and appointments? – Chirag Patel Apr 17 at 7:11
  • no relation is needed ,Actually I want to add user's email and name and id instead of created_by column as a columns @ChiragPatel – Arun karthi Mani Apr 17 at 7:42

1 Answer 1

active oldest votes
up vote 0 down vote
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.680815 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO