Laravel Classroom image

Anil  Bist / Professional / Web Technology

 
To post your Question Join Classroom
 
Lesson Topics's No:-  First|1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9|Last
Lessons:-Fluent Query Builder

10.3 Table Joins
Let’s have a look at a join using Fluent.
1 <?php
2
3 DB::table('tasks')
4 ->join('project', 'tasks.id', '=', 'project.task_id')
5 ->get(array('task.name', 'project.name'));We pass the name of the join table as the first parameter, and use the remaining three parameters
to perform an ‘ON’ clause, similar to how we perform ‘WHERE’s.
We then pass the fields we want to return to the get() method as an array.
We can do a left_join() exactly the same way, in fact it takes the same parameters, easy huh?
Do you remember the nested where clauses? Well you can use a similar technique to add more
conditions to the ON clause of a join. Let’s take a look.
1 <?php
2
3 DB::table('tasks')
4 ->join('project', function($join) {
5 $join->on('tasks.id', '=', 'project.task_id');
6 $join->or_on('tasks.author_id', '=', 'project.author_id');
7 })
8 ->get(array('task.name', 'project.name'));
In this case, we pass a closure as the second parameter to the join() method, then use the on(),
or_on() and and_on() methods to set the conditions.

 

 
 
 
image
Anil  Bist

Skills    Laravel

Qualifications :- High School - SLV, College/University - Graphic Era Deemed Univ University,
Location :-Dehradun,Dehradun,Uttarakhand,India
Description:-

I started my Professional Journey in 2006 with one of the Web Development Company in Bangalore and my 1st framework was "Ruby on Rail" as Web development and delivered around 5+ Projects using this platform. Then came another dimension as JEE/Sturst framework, Gradually I realized that I want to build something on my own and give my passion and energy on creating something different a
Explore

 

  Students (0)