Replies: 8 comments
-
@yajra Can you please suggest |
Beta Was this translation helpful? Give feedback.
-
I don't know what's going on in If you need the ID of an other model you can always call the relationship to get it |
Beta Was this translation helpful? Give feedback.
-
@Arne1303 myCompany() is not just adding a where condition I also try by removing this but the same issue in my company_users table only one record right now and the primary key is 4 And here is the response where the primary is overwritten by the user table primary key also notice it does not work $hidden as you can see 'password', and 'remember_token' also display if I try to get its id by ->id it gives me 1 but it should be 4 I use sort by users.first_name |
Beta Was this translation helpful? Give feedback.
-
Can you send the user relation definition in user company? |
Beta Was this translation helpful? Give feedback.
-
@Arne1303 |
Beta Was this translation helpful? Give feedback.
-
I can't find anything wrong with it, it should give you the ID of the company user. You could try specifying the table in a select statement and check if you are really viewing the right database in your DBMS |
Beta Was this translation helpful? Give feedback.
-
I think you just need to specify a select SQL: CompanyUsers::myCompany()->select('company_users.*')->has('users')->with('users'); |
Beta Was this translation helpful? Give feedback.
-
Yes after doing that it works |
Beta Was this translation helpful? Give feedback.
-
Overwrite the parent table primary key (id) by relation table when use has on the relation
I have 2 table
1) company_user
id -> primary key
company_id ->foreign key of company table
users_id -> foreign key of the user table
status
users (Laravel Default )
so when I tun
$models = CompanyUsers::myCompany()->has('users')->with('users');
return Datatables::eloquent($models)
->addIndexColumn()
->addColumn('check_box', function ($model) {
return view('common.checkbox', ['model' => $model, 'class' => 'i-checks people-checkbox']);
})
->addColumn('name', function ($model) {
return $model->users->name;
})
->addColumn('status', 'common.status')
->addColumn('action', templatePath('users.action'))
->rawColumns(['action', 'status','name' ,'check_box'])
->make(true);
if I try to access $mode->id it gives me the user table id not the company user table
Beta Was this translation helpful? Give feedback.
All reactions