This query gets all employees whose name field is not empty (NULL).
×
Get Employees Where Name Is Not Null
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class Query_Controller extends Controller
{
public function index()
{
$data = DB::table('employee')->whereNotNull('name')->get();
echo "<pre>";
print_r($data->toArray());
}
}
This query gets all employees whose name field is NULL.
×
Get Employees with a Null Name
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class Query_Controller extends Controller
{
public function index()
{
$data = DB::table('employee')->whereNull('name')->get();
echo "<pre>";
print_r($data->toArray());
}
}
Fetches all employees whose id is 50000 or greater and displays the results.
×
Get Employees with ID 50000 or Higher
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class Query_Controller extends Controller
{
public function index()
{
$data = DB::table('employee')->where('id','>=',50000)->get();
echo "<pre>";
print_r($data->toArray());
}
}
This query gets employees whose ID is between 13 and 14, or between 10 and 90.
×
Get Employees Within Multiple ID Ranges
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class Query_Controller extends Controller
{
public function index()
{
$data = DB::table('employee')->whereBetween('id',[13,14])->orwhereBetween('id',[10,90])->get();
echo "<pre>";
print_r($data->toArray());
}
}
This query gets the highest id value from the employee table. It is useful for finding the latest or largest employee ID.
×
Get Maximum Employee ID
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class Query_Controller extends Controller
{
public function index()
{
$data = DB::table('employee')->max('id');
echo "<pre>";
print_r($data);
}
}
This query gets the name, email, and address of all employees from the employee table and displays the result as an array.
×
Get Selected Employee Details
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class Query_Controller extends Controller
{
public function index()
{
$data = DB::table('employee')->select('name','email','address')->get();
echo "<pre>";
print_r($data->toArray());
}
}
This query fetches the first 10 records from the employee table and displays the result as an array.
×
Get the First 10 Employees
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class Query_Controller extends Controller
{
public function index()
{
$data = DB::table('employee')->limit(10)->get();
echo "<pre>";
print_r($data->toArray());
}
}
This query creates a query to get the latest employee record based on the created_at column. It does not run the query yet.
×
Get the Latest Employee Record
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class Query_Controller extends Controller
{
public function index()
{
$data = DB::table('employee')->latest();
echo "<pre>";
print_r($data);
}
}
This query gets unique records from the employee table and displays the data.
×
Get Unique Employee Records
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class Query_Controller extends Controller
{
public function index()
{
$data = DB::table('employee')->distinct()->get();
echo "<pre>";
print_r($data->toArray());
}
}
Insert a New Contact Record with a Random Employee ID
Insert a New Contact Record with a Random Employee ID
Insert a New Contact Record with a Random Employee ID
This query adds a new record to the contact table. It generates a random ID between 11111 and 99999 and stores the mobile number 1234567890.
×
Insert a New Contact Record with a Random Employee ID
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class Query_Controller extends Controller
{
public function index()
{
DB::table('contact')->insert(['id'=> mt_rand(11111,99999),'mobile'=>1234567890]);
}
}