laravel get all records code example

Example 1: DB::table('users')->get(); id 1

$users = DB::table('users')where('id','=', $userid)->get();

Example 2: get all data eloquent laravel

Blog::all();

//example usage.
$posts = Blog::all();

Example 3: laravel where

$users = DB::table('users')
                ->whereMonth('created_at', '12')
                ->get();

Example 4: laravel eloquent get all records where

// Get all rows from Eloquent model
Model::get();
	//Get all the cars
    $cars = App\Models\Cars::get();

// Get all rows from Eloquent model where column matches the given value
Model::where('column', {value})->get();
	//Get all the blue cars
	$blue_cars = App\Models\Cars::where('color', 'blue')->get();
	//Get all the green cars
	$looking_for = 'green';
	$green_cars = App\Models\Cars::where('color', $looking_for)->get();

// Get all rows from Eloquent model where column is matched conditionally
Model::where('column', {condition}, {value})->get();
	//Get all the antique cars
    $antiques = App\Models\Cars::where('year', '<=', 2000)->get();

// Get all rows from Eloquent model with multiple where conditions
	//Get all the green antique cars
    $green_antiques = App\Models\Cars::where(
      [
        	['color', 'green'],
        	['year', '<=', 2000],
      ]
    )->get();

// For very large data sets use cursor() rather than get();
Model::where('column', {value})->cursor();
// Or limits
Model::where('column', {value})->limit({n})->get();
	// Get the first 10 green cars
	$some_green_cars = 
      App\Models\Cars::where('color', 'green')->limit(10)->get();

Example 5: laravel where

$users = DB::table('users')
                ->whereDate('created_at', '2016-12-31')
                ->get();

Tags:

Php Example