Tag Archives: laravel online course
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 ;
Laravel where between
DB::table(‘table_name’)->whereBetween(‘column_name’,[value1,value2])->get(); is used for where Between condition in laravel.
Laravel where Between clause Example
We are going to fetch data with whereBetween clause in laravel from the table emp.
DB::table('emp')->whereBetween('salary',[10000,20000])->get();
Will Generate the following query.
//Select * from emp where salary BETWEEN 10000 AND 20000 ;
Laravel or where
DB::table(‘table_name’)->where(‘column_name’, ‘condition’, value)->orWhere(‘column_name’,’condition’,value)->get(); is used for orWhere condition in laravel.
Laravel or where clause Example
We are going to fetch data with where clause in laravel from the table emp.
DB::table('emp')->where('salary', '=',10000)->orWhere('experience' = '1')->get();
Will Generate the following query.
//Select * from emp where salary = ‘10000’ or experience = ‘1’ ;
Laravel where clause
DB::table(‘table_name’)->where(‘column_name’, ‘contional_operator’, value)->get(); is used for where condition in laravel.
Laravel where clause Example 1
We are going to fetch data with where clause in laravel from the table emp.
DB::table('emp')->where('salary', '=',10000)->get();
Will Generate the following query.
//Select * from emp where salary = ‘10000’;
Laravel where clause Example 2
DB::table('emp')->where('salary', '<',10000)->get();
Will Generate the following query.
//Select * from emp where salary < '10000';
Laravel truncate table
DB::table(‘table_name’)->truncate(); is used to truncate table in laravel.
Laravel truncate table example
Below is the simple example for Laravel truncate table
DB::table('users')->tuncate();
Will truncate the users table.