eloquent get all records code example
Example 1: get all data eloquent laravel
Blog::all();
//example usage.
$posts = Blog::all();
Example 2: 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();