This query counts the total number of records in the employee table and returns the count.
×
Count Total 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')->count();
echo "<pre>";
print_r($data);
}
}
Create 100 Fake Employee Records Using Laravel Seeder
Create 100 Fake Employee Records Using Laravel Seeder
Create 100 Fake Employee Records Using Laravel Seeder
This seeder creates 100 employee records with random ID, name, email, address, date of joining, gender, and status using Faker, then saves them to the database.
×
Create 100 Fake Employee Records Using Laravel Seeder
<?php
namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use App\Models\Employee;
use Faker\Factory as Faker;
class EmployeeSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$faker = Faker::create();
for($i=0;$i<100;$i++){
$employee = new Employee;
$employee->emp_id = mt_rand(11111,99999);
$employee->name = $faker->name;
$employee->email = $faker->email;
$employee->address = $faker->address;
$employee->doj = $faker->date;
$employee->gender = 'M';
$employee->status = 1;
$employee->save();
}
}
}
We creating a controller that will return string data.
×
Create Controller for Return String
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class Home_Controller extends Controller
{
public function index($value='')
{
return "Wellcome to Home Controller <br>Value is :".$value;
}
public function show($value='')
{
return "Wellcome to Home Controller <br>Value is :".$value;
}
public function edit($value='')
{
return "Wellcome to Home Controller <br>Value is :".$value;
}
}
We creating a controller that will load view with data
×
Create Controller for View Load
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class View_Load_Controller extends Controller
{
public function index($value='')
{
return view('load_view_page')->with(['value'=>$value]);
}
}
This migration creates an employee table with employee ID, email, address, joining date, status, and timestamps. The down() method removes the table when the migration is rolled back.
×
Create Employee Table Using Laravel Migration
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('employee', function (Blueprint $table) {
$table->id();
$table->string('emp_id',65);
$table->string('email',65);
$table->text('address',150)->nullable();
$table->date('doj');
$table->boolean('status')->default(1);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('employee');
}
};
This migration creates a failed_jobs table to store information about Laravel jobs that fail during execution.
×
Create Failed Jobs Table Migration
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('failed_jobs', function (Blueprint $table) {
$table->id();
$table->string('uuid')->unique();
$table->text('connection');
$table->text('queue');
$table->longText('payload');
$table->longText('exception');
$table->timestamp('failed_at')->useCurrent();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('failed_jobs');
}
};
We creating a resource controller that will do create some important methods automatically.
×
Create Resource Controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class Resource_Controller extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}
This migration creates a users table with fields for user name, email, password, email verification, remember token, and timestamps. It also removes the users table when the migration is rolled back.
×
Create Users Table with Laravel Migration
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('users');
}
};
Deletes the employee record from the employee table where the ID is 39418.
×
Delete an Employee Record by 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('employee')->where('id',39418)->delete();
}
}