[go: up one dir, main page]

0% found this document useful (0 votes)
5 views4 pages

Laravel Code

The document outlines a Laravel web application with routes for employee management, including creating, editing, updating, and deleting employee records. It defines an employee controller that handles the logic for these operations and a view for displaying employee data in a table format. The application also includes authentication routes and a profile management feature.

Uploaded by

vackla two
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Laravel Code

The document outlines a Laravel web application with routes for employee management, including creating, editing, updating, and deleting employee records. It defines an employee controller that handles the logic for these operations and a view for displaying employee data in a table format. The application also includes authentication routes and a profile management feature.

Uploaded by

vackla two
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

ROUTE WEB.

PHP

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\employeecontroller;

Route::get('/', function () {
return view('welcome');
});

Auth::routes();

Route::get('/home', [App\Http\Controllers\HomeController::class,
'index'])->name('home');

Route::middleware('auth')->group(function () {
Route::view('about', 'about')->name('about');

Route::get('employee', [App\Http\Controllers\employeecontroller::class,
'index']);
Route::post('employee', [App\Http\Controllers\employeecontroller::class,
'index']);
Route::get('users', [\App\Http\Controllers\UserController::class,
'index'])->name('users.index');
Route::get('employee', [\App\Http\Controllers\employeecontroller::class,
'index'])->name('employee.index');
Route::get('employee/create',
[App\Http\Controllers\employeecontroller::class,
'create'])->name('employee.create');;
Route::post('employee', [App\Http\Controllers\employeecontroller::class,
'store'])->name('employee.store');
Route::get('employee/{id}/edit',
[App\Http\Controllers\employeecontroller::class,
'edit'])->name('employee.edit');
Route::put('employee/{id}/edit',
[App\Http\Controllers\employeecontroller::class,
'update'])->name('employee.update');
Route::get('employee/{id}/delete',
[App\Http\Controllers\employeecontroller::class,
'destroy'])->name('employee.delete');

Route::get('profile', [\App\Http\Controllers\ProfileController::class,
'show'])->name('profile.show');
Route::put('profile', [\App\Http\Controllers\ProfileController::class,
'update'])->name('profile.update');
});
EMPLOYEE INDEX

@extends('layouts.app')

@section('content')

<!-- Main content -->


<div class="content">
<div class="container-fluid">
<a href="{{ route('employee.create') }}" class="btn btn-info">Add New
Employee</a>
<div class="row">

<div class="card-head">

</div>

<div class="card-body">

<table class="table table-bordered table-stiped fs-1


text-black">

<thead>
<tr>
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Middle Name</th>
<th>Age</th>
<th>Address</th>
<th>Zip</th>
</tr>
</thead>

<tbody >
@foreach ($employees as $items)
<tr>

<td class="">{{$items-> id}}</td>


<td>{{$items-> fname}}</td>
<td>{{$items-> lname}}</td>
<td>{{$items-> midname}}</td>
<td>{{$items-> age}}</td>
<td>{{$items-> address}}</td>
<td>{{$items-> zip}}</td>
<td>
<span class="badge bg-success"><a href="{{
route('employee.edit', $items->id)}}" class="btn btn-success mx-3
"><h5>Edit</h5></a></span>
</td>
<td>

<span class="badge bg-danger"><a href="{{


route('employee.delete', $items->id)}}" class="m-3
p-lg-5"><h5>Delete</h5></a></span>
</td>

</tr>
@endforeach
</tbody>

</table>
</div>

<div class="card-footer">

</div>

<!-- /.row -->


</div><!-- /.container-fluid -->
</div>
<!-- /.content -->
@endsection
\

EMPLOYEE CONTROLLER

<?php

namespace App\Http\Controllers;
use Illuminate\Support\Fascades\DB;
use Response;
use Illuminate\Http\Request;
use App\Models\employee;

class employeecontroller extends Controller


{
public function index()
{
$employees = employee::get();
return view ('employee.index',compact('employees'));
}

public function create()


{
return view ('employee.create');
}

public function store(Request $request)


{
$request->validate([
'fname' => 'required|max:255|string',
'lname' => 'required|max:255|string',
'midname' => 'required|max:255|string',
'age' => 'required|integer',
'address' => 'required|max:255|string',
'zip' => 'required|integer',

]);

employee::create($request->all());
return view ('employee.create');
}

public function edit( int $id)


{
$employees = employee::find($id);
return view ('employee.edit', compact ('employees'));
}

public function update(Request $request, int $id) {


{
$request->validate([
'fname' => 'required|max:255|string',
'lname' => 'required|max:255|string',
'midname' => 'required|max:255|string',
'age' => 'required| integer',
'address' => 'required|max:255|string',
'zip' => 'required| integer',

]);

employee::findOrFail($id)->update($request->all());
return redirect ()->back()->with('status','Employee Updated
Successfully!');
}
}

public function destroy(int $id){


$employees = employee::findOrFail($id);
$employees->delete();
return redirect ()->back()->with('status','Employee Deleted');
}
}

You might also like