Get Records or Retrieving records

Select record in laravel in list,select on multiple conditon,select distinct record from db,multiple where conditon,select record orderby between,having,limit.

Database in Laravel

Get Records or Retrieving records:

Here table name is users

Get All Record From table
    	$users = DB::table('users')->get();
        print_r($users);
    

Here table name is users and John is name which are find from data base.

Get Single Record From table
    	$user = DB::table('users')->where('name', 'John')->first();
        print_r($users);
    

Here table name is users and John is name which are find from data base and pluck(‘name’) is column name which are get

Get Single Column From database of a row
    	$name = DB::table('users')->where('name', 'John')->pluck('name');
        print_r($name);
    

Here table name is users and name is the column in users which are get of all record.The lists are used to get the list of records from database.

Get List of single column from database in laravel
    	$listname = DB::table('users')->lists('name');
        print_r($listname);
    

Here table name is users and name and id is the column in users which are get of all record.The lists are used to get the list of records from database.its return array of users;

Get List of multiple column from database in laravel
    	$users = DB::table('users')->lists('name', 'id');
        print_r($users);
    

Here table name is users and name and email is column name which are get.its return array of users;

Get Record according to selected filde name
    	$users = DB::table('users')->select('name', 'email')->get();
        print_r($users);
    

Here table name is users and distinct is used to get distinct record.its return array of users

Get distinct record from database in laravel
    	$users = DB::table('users')->distinct()->get();
        print_r($users);
    

Here table name is users age is coumn in users table.its return array of users. its return users which age is greater than 100.
conditions

Greater than : >
Greater than : <
Greater than : =
Get greter than or less than record from database in laravel
    	$users = DB::table('users')->where('age', '>', 100)->get();
        print_r($users);
    

Here table name is users.its return array of users

Multiple where condition in laravel
        $users = DB::table('users')
                    ->where('age', '>', 100)
                    ->orWhere('name', 'John')
                    ->get();
        print_r($users);
    

Here table name is users.its return array of users its return user which age belong form 50 to 100 list

Between condition in laravel
        $users = DB::table('users')
                    ->whereBetween('age', array(50, 100))->get();
        print_r($users);
    

Here table name is users.its return array of users its return user which age notbelong form 50 to 100 list

NotBetween condition in laravel
        $users = DB::table('users')
                    ->whereNotBetween('age', array(50, 100))->get();
        print_r($users);
    

Here table name is users.

Using Where In With An Array
        $users = DB::table('users')
                    ->whereIn('id', array(1, 2, 3))->get();
        print_r($users);
    

Here table name is users.job is the field in user.

Select record group by
        $users = DB::table('users')
                    ->groupBy('job')
                    ->get();
        print_r($users);
    

Here table name is users.job is the field in user.

Select record Having by
        $users = DB::table('users')
                    ->groupBy('job','>', 100)
                    ->get();
        print_r($users);
    

Here table name is users.job is the field in user.

Select record order by
        $users = DB::table('users')
                    ->orderBy('name', 'desc')
                    ->get();
        print_r($users);
    

Here table name is users.job is the field in user.the take key word used for limit.

Select record with limit
        $$users = DB::table('users')->take(5)->get();
        print_r($users);
    
Share Button

About admin

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Author: pramod kumar kumawat Mob: 9269727062
Free WordPress Themes - Download High-quality Templates