Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merging data from multiple table into 1 data table #178

Open
bczm8703 opened this issue Dec 5, 2014 · 5 comments
Open

Merging data from multiple table into 1 data table #178

bczm8703 opened this issue Dec 5, 2014 · 5 comments
Labels

Comments

@bczm8703
Copy link

bczm8703 commented Dec 5, 2014

Hi. I would like to check whether is it possible to merge data from more than 1 table in a datatable.
Eg:

  • leave table having column: Employee Name, Leave Type, start_date, end_date, status
  • Off table having column: Employee Name, Off Type, start_date, end_date, status
  • Mc table having column: Employee Name, Reason, date, status

Therefore is it possible to get all the record from this 3 tables and put them into 1 datatable?

@MarkVaughn
Copy link
Contributor

You mean how to do a SQL JOIN?
DB::table('leave')->select([..yourcolumns..])->join('off'.....
What code do you have so far?

@bczm8703
Copy link
Author

bczm8703 commented Dec 5, 2014

I am able tl extract the individual data from their respective table eg:
Leave::select('status', 'start_date', 'end_date', 'type');

I cant join them with sql as their column name are different... is there anyway to merge the data of different eloquent into 1?

@MarkVaughn
Copy link
Contributor

Honestly I don't really understand what you mean by merge. If you use
JOIN, you can SELECT with aliases e:g: 'off.start_date AS
off_start_date',' leave.start_date AS leave_start_date' etc....

Mark Vaughn
Mobile: +1 (770) 533-2274

On Fri, Dec 5, 2014 at 11:50 AM, bczm8703 [email protected] wrote:

I am able tl extract the individual data from their respective table eg:
Leave::select('status', 'start_date', 'end_date', 'type');

I cant join them with sql as their column name are different... is there
anyway to merge the data of different eloquent into 1?


Reply to this email directly or view it on GitHub
#178 (comment)
.

@bczm8703
Copy link
Author

bczm8703 commented Dec 8, 2014

sorry for not being clear with my question. what i meant is;
for example i have 3 tables in my database. Leave table, MC table and Off table.

if i wanted to use a data table for each of this table i would do this;

  • $leaves = Leave::where('status', 'pending')->select('employee_name', 'leave_type', 'leave_start_date', 'leave_end_date', 'status')->orderBy('created_at', 'desc');
  • $offs = Off::where('status', 'pending')->select('employee_name', 'off_start_date', 'off_end_date', 'status')->orderBy('created_at', 'desc');
  • $mcs = Mc::where('status', 'pending')->select('employee_name', 'mc_date', 'reason', 'status')->orderBy('created_at', 'desc');

My question now is, is it possible for $leaves, $offs and $mcs to be place into 1 data table only?

@phazei
Copy link
Contributor

phazei commented Dec 8, 2014

Yes, it is possible. Look at example 6 of the readme. In that, the profiles table is being joined with the user table and it displays data from both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants