php - display data from database based on other column table laravel 5
I want to display data from spesific column users table, let say uiprv column. and uiprv same as id from provinsi table.
This is User table image:
and this is provinsi table:
and now, I've succesfully display data from database but just show "31". 31 is uiprv column from users table, it same thing with id from provinsi table. the question is, how to display data not just 31 , but it can be DKI JAKARTA . like in nama_provinsi at provinsi table .
How should I write code in my controller for this. Thanks in Advance.
Answer
Solution:
Add this in your App/User.php
From what you've written,
Relationship between User to Province is Many to one.
Reference - https://laravel.com/docs/5.3/eloquent-relationships
Answer
Solution:
In your User Model add this
And in your controller do this
Answer
Solution:
You can write a join query to fetch the specific column from table.
e.g.
Answer
Solution:
Add this in your user model,
or
you can add some other fields also in the select.
Try these and reply for this answer.