Employee Registration with File Upload and Database Storage
This code registers a new employee. It validates the employee details, uploads the employee file, creates a unique employee ID, saves the employee information in the database, and sets the employee status as active.
×
Employee Registration with File Upload and Database Storage
This query fetches all employees except the employee whose id is 50000.
×
Exclude Employee by 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')->where('id','<>',50000)->get();
echo "<pre>";
print_r($data->toArray());
}
}
This query skips the first 5 employee records and fetches the next 10 records from the employee table. The result is then converted into an array and displayed.
×
Fetch 10 Employees After Skipping the First 5
<?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')->offset(5)->limit(10)->get();
echo "<pre>";
print_r($data->toArray());
}
}
This query gets all employee names from the employee table using Laravel's pluck() method and displays them as an array.
×
Fetch All Employee Names Using Laravel Pluck
<?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')->pluck('name');
echo "<pre>";
print_r($data->toArray());
}
}
Retrieves all records from the employee table and displays them in a readable array format.
×
Fetch All 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')->get();
echo "<pre>";
print_r($data->toArray());
}
}
Retrieves all employees from the employee table whose address is india and displays the results as an array.
×
Fetch Employees by Address
<?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('address','india')->get();
echo "<pre>";
print_r($data->toArray());
}
}
Fetches all employees from the employee table whose address is "india" and gender is "O". Displays the matching records as an array.
×
Fetch Employees by Address and Gender
<?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(['address'=>'india','gender'=>'O'])->get();
echo "<pre>";
print_r($data->toArray());
}
}
This query fetches employees whose IDs are 1, 5, or 10 from the employee table.
×
Fetch Employees by Multiple IDs
<?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')->whereIn('id',[1,5,10])->get();
echo "<pre>";
print_r($data->toArray());
}
}
This query gets employees whose address is either exactly "America" or contains the word "India".
×
Fetch Employees from America or India
<?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('address','America')->orwhere('address','like','%india%')->get();
echo "<pre>";
print_r($data->toArray());
}
}
This query retrieves all employees from the employee table whose address is india and gender is O. It displays the results as an array.
×
Fetch Employees from India with Gender O
<?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('address','india')->where('gender','O')->get();
echo "<pre>";
print_r($data->toArray());
}
}