MINI PROJECT OF EMPLOYEE MANAGEMENT SYSTEM USING PHP LARAVEL FRAMEWORK CRUD OPERATION (CREATE, READ, UPDATE AND DELETE) INCLUDING INTRODUCTION, LEARNING OBJECTIVE, BODY, LEARNING OUTCOME, BIBLIOGRAPHY, ACKNOWLEDGEMENT AND CONCLUSION
MINI PROJECT OF EMPLOYEE MANAGEMENT SYSTEM USING PHP LARAVEL FRAMEWORK CRUD OPERATION (CREATE, READ, UPDATE AND DELETE) INCLUDING INTRODUCTION, LEARNING OBJECTIVE, BODY, LEARNING OUTCOME, BIBLIOGRAPHY, ACKNOWLEDGEMENT AND CONCLUSION
INTRODUCTION =>
In this mini project I will be creating a CRUD Operation (Create, Read, Update And Delete) using PHP Laravel Framework of Employee Management System where I will be having the six database fields in a table like employee_id, name, position, department, email and finally date_hired where I can add new employees details, list all employees details, edit an employee information and delete an employee records. Laravel Framework is basically a framework of PHP which is much more secure than any other frameworks of PHP like CodeIgnitor, etc.
LEARNING OBJECTIVE =>
In Learning Objective, I will learn about how to add new employee details, how to list all employee details, how to edit an employee information and how to delete an employee records. So, in Learning Objective, I will learn about this four steps Create, Read, Update and Delete.
BODY =>
STEP 1 : First I have created a Database in phpMyAdmin and the Database which I have created is "employeeDB" as shown in the image below.
STEP 2: Once my Database "employeeDB" is created, I have created a table whose name I have provided as "employees" with Number of columns as 6 because I will be having 6 fields in my table as shown in the image below.
STEP 3: Once my Database Table "employees" is created I have input the 6 fields in the table. My 1st field is employee_id whose type is VARCHAR and Length/Values is 100, 2nd field is name whose type is VARCHAR and Length/Values is 100, 3rd field is position whose type is VARCHAR and Length/Values is 100, 4th field is department whose type is VARCHAR and Length/Values is 100, 5th field is email whose type is VARCHAR and Length/Values is 100 and the last and final field is date_hired whose type is DATE and then I need to click on the Save button as shown in the image below.
PS C:\xampp\htdocs\Ayan_Home\Laravel\myApp> php artisan make:view employee
INFO View [C:\xampp\htdocs\Ayan_Home\Laravel\myApp\resources\views\employee.blade.php] created successfully.
STEP 5: Once my employee.blade.php is created I need to create a form structure in employee.blade.php as shown below.
employee.blade.php :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Employee Management System</title>
<!--Add Bootstrap-4 CDN -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
</head>
<body>
<div class="container-fluid">
<header class="modal-header">
<h1>Employees</h1>
</header>
<form method="POST" action="{{url('/submit')}}">
@csrf
<div class="form-group">
<div class="row">
<div class="col">Name: <input type="text" name="nm" id="nm" required class="form-control"></div>
<div class="col">Position: <input type="text" name="ps" id="ps" required class="form-control"></div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col">Department: <input type="text" name="dpt" id="dpt" required class="form-control"></div>
<div class="col">Email: <input type="text" name="em" id="em" required class="form-control"></div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col">Date_Hired: <input type="date" name="dh" id="dh" required class="form-control"></div>
</div>
</div>
<div class="form-group">
<button class="btn btn-sm btn-outline-primary">Submit</button>
</div>
</form>
@if(session() -> has('message'))
@if(session() -> get('message')=='employeeadded')
<div class="alert alert-success">Employee Add Done!</div>
@endif
@endif
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Employee Management System</title>
<!--Add Bootstrap-4 CDN -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
</head>
<body>
<div class="container-fluid">
<header class="modal-header">
<h1>Employees</h1>
</header>
<form method="POST" action="{{url('/submit')}}">
@csrf
<div class="form-group">
<div class="row">
<div class="col">Name: <input type="text" name="nm" id="nm" required class="form-control"></div>
<div class="col">Position: <input type="text" name="ps" id="ps" required class="form-control"></div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col">Department: <input type="text" name="dpt" id="dpt" required class="form-control"></div>
<div class="col">Email: <input type="text" name="em" id="em" required class="form-control"></div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col">Date_Hired: <input type="date" name="dh" id="dh" required class="form-control"></div>
</div>
</div>
<div class="form-group">
<button class="btn btn-sm btn-outline-primary">Submit</button>
</div>
</form>
@if(session() -> has('message'))
@if(session() -> get('message')=='employeeadded')
<div class="alert alert-success">Employee Add Done!</div>
@endif
@endif
</div>
</body>
</html>
STEP 6: Then I will be creating EmployeesController.php by using the command "php artisan make:controller EmployeesController"and once I enter the command in composer command prompt my EmployeesController.php page will be created below Controllers as shown in the image below.
STEP 7: Once my EmployeesController.php is created I need to create a form structure in EmployeesController.php as shown below.
EmployeesController.php :
STEP 10: Then I have put the path of "/employees/all", "/employee" and "/submit" in web.php page.
STEP 11: Then I need to change the database name i.e. DB_DATABASE name to employeeDB in .env file as shown in the image below.
Step 12: Now I have just filled the Employees Form from the path "http://localhost:1234/employee" and click on Submit button as shown below in the image.
STEP 13: After filling out the Employees Form I will be able to see the display page of "Displaying All Employee Details" in the path "http://localhost:1234/employees/all" as shown in the image below.
STEP 14: Once I click on the button Print or SaveAs PDF button, it will allow me to print the displaying all tasks if I have printer otherwise it will allow me to save as SaveAs PDF option as shown in the image below.
STEP 15: So, in my first part I have shown how to create and add the employee details in CRUD Operation using PHP Laravel Framework.
showallemployee.blade.php page :
<td><a href="{{url('employees/show')}}/{{$employee->employee_id}}" class="btn btn-sm btn-outline-primary">View</td>
@if(session()->has("message")) @if(session()->get("message")=="delete_success") <div class="alert alert-success">One Employee's detail has been removed successfully!</div> @elseif(session()->get("message")=="delete_error") <div class="alert alert-danger">Unable to delete Employee !</div> @endif @endif
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<!--Add Bootstrap-4 CDN -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
</head>
<body>
@if(!empty($employees))
<fieldset class="card p-5 m-5">
<legend>
<h2>Displaying All Employees Details:</h2>
</legend>
@if(session()->has("message"))
@if(session()->get("message")=="delete_success")
<div class="alert alert-success">One Employee's detail has been removed successfully!</div>
@elseif(session()->get("message")=="delete_error")
<div class="alert alert-danger">Unable to delete Employee !</div>
@endif
@endif
<div class="table-responsive">
<table class="table table-hover">
<tr>
<th>Employee_ID:</th>
<th>Name:</th>
<th>Position:</th>
<th>Department:</th>
<th>Email:</th>
<th>Date_Hired:</th>
</tr>
@foreach($employees as $employee)
<tr>
<td><a href="{{url('employees/show')}}/{{$employee->employee_id}}" class="btn btn-sm btn-outline-primary">View</a></td>
<td>{{$employee->employee_id}}</td>
<td>{{$employee->name}}</td>
<td>{{$employee->position}}</td>
<td>{{$employee->department}}</td>
<td>{{$employee->email}}</td>
<td>{{$employee->date_hired}}</td>
</tr>
@endforeach
</table>
</div>
</fieldset>
<div align="center">
<button class="btn btn-primary" onclick="window.print();">Print or SaveAs PDF:</button>
</div>
@endif
</body>
</html>
Now I will be adding the below codes in EmployeesController.php page to view the employee details and delete an employee record.
EmployeesController.php page :
STEP 16: Now I will be creating showemployee.blade.php page using the composer command "php artisan make: view showemployee" as shown in the image below.
PS C:\xampp\htdocs\Ayan_Home\Laravel\myApp> php artisan make:view showemployee
INFO View [C:\xampp\htdocs\Ayan_Home\Laravel\myApp\resources\views\showemployee.blade.php] created successfully.
STEP 17: Once my showemployee.blade.php is created I need to create a form structure in showemployee.blade.php as shown below.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Employee Management System</title>
<!--Add Bootstrap-4 CDN -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
</head>
<body>
<div class="container-fluid">
<header class="modal-header">
<h1>Employees</h1>
</header>
@if(!empty($employee))
<form method="POST" action="{{url('/submit')}}">
@csrf
<div class="form-group">
<div class="row">
@php
$nameArr=explode(" ",$employee->name);
@endphp
<div class="col">Name: <input type="text" name="nm" id="nm" required class="form-control" value="{{$nameArr[0]}}"></div>
<div class="col">Position: <input type="text" name="ps" id="ps" required class="form-control" value="{{$employee->position}}"></div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col">Department: <input type="text" name="dpt" id="dpt" required class="form-control" value="{{$employee->department}}"></div>
<div class="col">Email: <input type="text" name="em" id="em" required class="form-control" value="{{$employee->email}}"></div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col">Date_Hired: <input type="date" name="dh" id="dh" required class="form-control" value="{{$employee->date_hired}}"></div>
</div>
</div>
<div align="center" class="form-group">
<button class="btn btn-sm btn-outline-primary">UPDATE</button>
<a href="{{url('employees/delete')}}/{{$employee->employee_id}}" onclick="return confirm('Do you want to delete this record ?');" class="btn btn-sm btn-outline-danger">DELETE</a>
</div>
</form>
@endif
</div>
</body>
</html>
STEP 18: Now I have put the below codes of "/employees/showemployee/{uid}"
and "/employees/delete/{uid}" in web.php page as shown in the image below.
STEP 19: Now I can see the employee details along with view, UPDATE and DELETE button as shown in the image below.
STEP 20: Once I click on Delete Button it will prompt me "Do you want to delete this button?" Ok or Cancel. If I click on Ok, the employees details will be deleted and if I click on Cancel, the employees details will not be deleted. And if I click on OK, then after delete it will let me know that " One Employee's details has been removed successfully!" as shown in the image below otherwise it will prompt me unable to delete employee!.
STEP 21: Now I need to view and edit an employee information. So, to do so, I have add the below codes in "showemployee.blade.php" and in "EmployeesController.php" and also I have added the update path "/employees/update/{uid}" in web.php page as shown in the image below.
<form method="POST" action="{{url('/employees/update')}}/{{$employee->employee_id}}" novalidate>
EmployeesController.php :
web.php :
LEARNING OUTCOME =>
In Learning Outcome, I have learnt about how to add new employee details, how to list all employee details, how to edit an employee information and how to delete an employee records. So, in Learning Outcome, I have basically learnt about this four steps Create, Read, Update and Delete.
BIBLIOGRAPHY =>
In bibliography I like to mention that I have taken this unsolved example of Employee Management System Of Laravel CRUD Operation from CHAT GPT. Then I have performed the Laravel CRUD Operation on my own with reference to the way Satindra Sir has taught the Laraavel CRUD Operations in our class without taking any help of any codes from CHAT GPT/MICROSOFT COPILOT/ANY AI TOOLS.
ACKNOWLEDGEMENT =>
In acknowledgement, I really like to thanks my respected teachers of ejobindia (Gargi Pramanik Mam and Satindra Bose Sir) for motivating me & encouraging me everytime and stand beside me when I run through tough times. For that I really like to express my high gratitude towards my respected teachers. And beside I also like to thanks and express my gratitude to my batch mates (Sayanti Karamakar, Parnashri Das Adhikari, Anish Guha & Debanjan Das) for helping me whenever any help is needed from my end in this running 5 months course of PHP Laravel Web Development Course.
CONCLUSION =>
Here I like to conclude by briefing that PHP Laravel CRUD Operation is one of the most important topic of the course as well as CRUD Operation itself is very much more essential in IT industries (Development Sector). And in IT Industry PHP Developers need to work mainly on CRUD Operations and Laravel Framework to add the users details, or update the users details, or view the users details or to delete the users details to help the global clients based on the demands of projects assigned by the clients to IT Industries. That's why CRUD Operation is very important and not only CRUD Operation, PHP Laravel CRUD Operation is very important.
Comments
Post a Comment