1

hi im fairly new in laravel 4.2 so i have this table (table 1) which gets data from a related table (table 2) but table 2 also gets from another related table (table 3) here is a visualization enter image description here

im using laravel 4.2 query builder for this here is my sample code on how im connecting table 1 and table 2

$records = DB::table('table1')
            ->join('table2', 'table1.someID', '=', 'table2.someID')
            ->select('select something')
            ->get();

my problem is i don't know how to get the values from table 3 is there a way for this? any help would be appreciated

3
  • 1
    Maybe add another join for table 3? ->join('table3', 'table3.someID', '=', 'table2.someID') Commented Oct 18, 2015 at 8:31
  • will try that out. thanks! Commented Oct 18, 2015 at 8:32
  • 1
    that did the trick! thanks :) can you put your answer below? Commented Oct 18, 2015 at 8:34

1 Answer 1

1

Umm.. I don't really mind but, here you go. You just have to put another join to get the values to the third table from the table 2 judging from the visual above.

$records = DB::table('table1')
            ->join('table2', 'table1.someID', '=', 'table2.someID')
            ->join('table3', 'table3.someID', '=', 'table2.someID')
            ->select('select something')
            ->get();
Sign up to request clarification or add additional context in comments.

1 Comment

No problem, never thought I would be much help. Glad I helped you. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.