Tag Archives: laravel tutorials for beginners

Laravel right join query example


Laravel right join query example : DB::table(‘table_name’)->rightJoin(‘condition’)->select(‘column_names’)->get(); is used for right join in laravel.


Laravel right join query example

DB::table('users')
          ->rightJoin('city','city.user_id','=','users.id')
          ->select('users.name','city.city_name')
         ->get();

Laravel left join query example


Laravel left join query example : DB::table(‘table_name’)->leftJoin(‘condition’)->select(‘column_names’)->get(); is used for join in laravel.


Laravel left join query example

DB::table('users')
          ->leftJoin('city','city.user_id','=','users.id')
          ->select('users.name','city.city_name')
         ->get();

Laravel Get Base Url


Laravel Get Base Url : You Can the get base url in laravel as below.


Laravel Get Base Url Syntax


 $baseurl = url();

Which will the give base url of the application.

Laravel group by


DB::table(‘table_name’)->groupBy(‘column_name’)->get(); is used for group by condition in laravel.


laravel group by clause Example

We are going to fetch data with groupBy clause in laravel from the table emp.

DB::table('emp')->groupBy('manager_name')->get();

Will Generate the following query.

//Select * from emp group BY ‘manage_name’ ;

Laravel order by ASC DESC


DB::table(‘table_name’)->orderBy(‘column_name’,’DESC_ASC’)->get(); is used for order by condition in laravel.
Where first parameter is column name and second parameter is direction of order ie. DESC or ASC.


Laravel order by ASC clause Example – ASC order

We are going to fetch data with orderBy clause in laravel from the table emp.

DB::table('emp')->orderBy('name', 'asc')->get();

Will Generate query like this.

//Select * from emp order by name ASC ;

Laravel order by DESC clause Example – DESC order

We are going to fetch data with orderBy clause in laravel from the table emp.

DB::table('emp')->orderBy('name', 'desc')->get();

Will Generate query like this.

//Select * from emp order by name DESC;

Laravel where not null


DB::table(‘table_name’)->whereNotNull(‘column_name’)->get(); is used for where Not Null condition in laravel.


Laravel where not null clause Example

We are going to fetch data with whereNotNull clause in laravel from the table emp.

DB::table('emp')->whereNotNUll('manager_name')->get();

Will Generate query like this.

//Select * from emp where manager_name IS NOT NUll ;

Laravel where not in


DB::table(‘table_name’)->whereNotIn(‘column_name’,[value1,value2,value3….])->get(); is used for where NotIn condition in laravel.


Laravel where Not In clause Example

We are going to fetch data with whereNotIn clause in laravel from the table emp.

DB::table('emp')->whereNotIn('salary',[10000,20000,30000])->get();

Will Generate the following query.

//Select * from emp where salary NOT IN (10000, 20000, 30000) ;

Laravel where in


DB::table(‘table_name’)->whereIn(‘column_name’,[value1,value2,value3….])->get(); is used for where In condition in laravel.


Laravel where In clause Example

We are going to fetch data with whereIn clause in laravel from the table emp.

DB::table('emp')->whereIn('salary',[10000,20000,30000])->get();

Will Generate the following query.

//Select * from emp where salary IN (10000, 20000, 30000) ;

Laravel where not between


DB::table(‘table_name’)->whereNotBetween(‘column_name’,[value1,value2])->get(); is used for where NotBetween condition in laravel.


Laravel where Not Between clause Example

We are going to fetch data with whereNotBetween clause in laravel from the table emp.

DB::table('emp')->whereNotBetween('salary',[10000,20000])->get();

Will Generate the following query.

//Select * from emp where salary NOT BETWEEN 10000 AND 20000 ;