Laravel Query Builder Part -01 (Basic)
Basic query builder for starting…
Getting all specific column values from all rows
Example: Gettings all emails from the user’s tables
Code:
//gettings all email from the users tables
$users = DB::table('users')->get();
foreach($users as $user){
$all_email = $user->email;
echo $all_email;
}Getting Specific rows from the tables
Example: Gettings 3rd row of the user's tables
Get Ruman Ahmed’s stories in your inbox
Join Medium for free to get updates from this writer.
Code:
//gettings 3rd row of products tables
$products = DB::Table('products')->first(3);
return $products;Gettings key-value pair from a single table
Example: Return a key value from brands tables (brandName is value and id is key)
Code:
//gettings key-value or associative array from brands table
$brands = DB::Table('brands')->pluck('brandName','id');
return $brands;Next part link: Laravel Query Builder — (Part-02)










