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();
$posts = Blog::all();
Example 3: laravel where
$users = DB::table('users')
->whereMonth('created_at', '12')
->get();
Example 4: laravel eloquent get all records where
Model::get();
$cars = App\Models\Cars::get();
Model::where('column', {value})->get();
$blue_cars = App\Models\Cars::where('color', 'blue')->get();
$looking_for = 'green';
$green_cars = App\Models\Cars::where('color', $looking_for)->get();
Model::where('column', {condition}, {value})->get();
$antiques = App\Models\Cars::where('year', '<=', 2000)->get();
$green_antiques = App\Models\Cars::where(
[
['color', 'green'],
['year', '<=', 2000],
]
)->get();
Model::where('column', {value})->cursor();
Model::where('column', {value})->limit({n})->get();
$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();