Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel query buider

// Retrieving All Rows From A Table
DB::table('name')->get();
// Chunking Results From A Table
DB::table('users')->chunk(100, function($users)
{
  foreach ($users as $user)
  {
      
//
}
});
// Retrieving A Single Row From A Table
$user = DB::table('users')->where('name', 'John')->first();
DB::table('name')->first();
// Retrieving A Single Column From A Row
$name = DB::table('users')->where('name', 'John')->pluck('name');
DB::table('name')->pluck('column');
// Retrieving A List Of Column Values
$roles = DB::table('roles')->lists('title');
$roles = DB::table('roles')->lists('title', 'name');
// Specifying A Select Clause
$users = DB::table('users')->select('name', 'email')->get();
$users = DB::table('users')->distinct()->get();
$users = DB::table('users')->select('name as user_name')->get();
// Adding A Select Clause To An Existing Query
$query = DB::table('users')->select('name');
$users = $query->addSelect('age')->get();
// Using Where Operators
$users = DB::table('users')->where('votes', '>', 100)->get();
$users = DB::table('users')
              ->where('votes', '>', 100)
              ->orWhere('name', 'John')
              ->get();
$users = DB::table('users')
              ->whereBetween('votes', [1, 100])->get();
$users = DB::table('users')
              ->whereNotBetween('votes', [1, 100])->get();
$users = DB::table('users')
              ->whereIn('id', [1, 2, 3])->get();
$users = DB::table('users')
              ->whereNotIn('id', [1, 2, 3])->get();
$users = DB::table('users')
              ->whereNull('updated_at')->get();
DB::table('name')->whereNotNull('column')->get();
// Dynamic Where Clauses
$admin = DB::table('users')->whereId(1)->first();
$john = DB::table('users')
              ->whereIdAndEmail(2, 'john@doe.com')
              ->first();
$jane = DB::table('users')
              ->whereNameOrAge('Jane', 22)
              ->first();
// Order By, Group By, And Having
$users = DB::table('users')
              ->orderBy('name', 'desc')
              ->groupBy('count')
              ->having('count', '>', 100)
              ->get();
DB::table('name')->orderBy('column')->get();
DB::table('name')->orderBy('column','desc')->get();
DB::table('name')->having('count', '>', 100)->get();
// Offset & Limit
$users = DB::table('users')->skip(10)->take(5)->get();
Comment

PREVIOUS NEXT
Code Example
Php :: laravel join with count 
Php :: custom-taxonomy-image-option-in-admin-panel 
Php :: how to put external file in laravel listener class 
Php :: /usr/local/bin/php /home/tbmholdingltd/public_html/tugent/php artisan schedule:run /dev/null 2&1 
Php :: source code in html to add two numbers together 
Php :: phpstorm entity identification 
Php :: Warning: Undefined array key "index_no" in C:xampphtdocs ruestudent eports.php on line 54 Fatal error: Uncaught TypeError: mysqli_fetch_array(): 
Php :: Automatically downloading images from any URL location 
Php :: many to many relationship laravel example 
Php :: php docblock 
Php :: WooCommerce quantity field to ajax add to cart button archive page 
Php :: Obtener rol de usuario registrado en WordPress 
Php :: laravel eloquent where value less then 5 and greter then 0 
Php :: sail laravel mix hot 
Php :: login with google account using php source code download 
Php :: sql update views +1 
Php :: MySQL eqSql Connection 
Php :: Failed to open stream: No such file or directory in /home/southsah/public_html/wp-content/advanced-cache.php on line 22 
Php :: $this-uri-uri_to_assoc(5); 
Php :: forPage return keys on page 2 
Php :: sync fetch eloquent laravel 
Php :: concatenar 
Php :: wp_ajax_nopriv 
Php :: search highlighting 
Php :: generate hash password in laravel online 
Php :: Laravel API ResourceCollection doesnt works 
Php :: 7 reasons why Lee is an idiot 
Php :: : in php 
Php :: php json array push in js file 
Php :: Explicit Octal numeral notation - PHP 8.1 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =