employee crud

This commit is contained in:
Ranjan 2024-04-10 15:15:24 +05:45
parent d92366b1f4
commit b5c603ceec
13 changed files with 420 additions and 194 deletions

View File

@ -3,18 +3,25 @@
namespace Modules\Employee\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Models\Role;
use Carbon\Carbon;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Modules\Employee\Repositories\EmployeeInterface;
use Modules\User\Repositories\UserInterface;
class EmployeeController extends Controller
{
private EmployeeInterface $employeeRepository;
private $employeeRepository;
private $userRepository;
public function __construct(EmployeeInterface $employeeRepository)
public function __construct(EmployeeInterface $employeeRepository, UserInterface $userRepository)
{
$this->employeeRepository = $employeeRepository;
$this->userRepository = $userRepository;
}
/**
* Display a listing of the resource.
@ -22,6 +29,8 @@ class EmployeeController extends Controller
public function index()
{
$data['employees'] = $this->employeeRepository->findAll();
$data['roleLists'] = Role::pluck('name', 'id');
// dd($data['employees']->toArray());
return view('employee::index', $data);
}
@ -31,6 +40,11 @@ class EmployeeController extends Controller
public function create()
{
$data['title'] = 'Create Employee';
$data['departmentList'] = [];
$data['designationList'] = [];
$data['genderList'] = [];
$data['nationalityList'] = [];
return view('employee::create', $data);
}
@ -39,22 +53,20 @@ class EmployeeController extends Controller
*/
public function store(Request $request)
{
$inputData = $request->only(['first_name', 'last_name']);
// try {
$inputData = $request->all();
try {
if ($request->hasFile('profile_pic')) {
$fileName = time() . '_' . $request->profile_pic->getClientOriginalName();
$filePath = $request->file('profile_pic')->storeAs('uploads', $fileName, 'public');
$inputData['profile_picture'] = time() . '_' . $request->profile_pic->getClientOriginalName();
// $fileModel->file_path = '/storage/' . $filePath;
// $fileModel->save();
if ($request->hasFile('profile_pic')) {
$fileName = time() . '_' . $request->profile_pic->getClientOriginalName();
$filePath = $request->file('profile_pic')->storeAs('uploads', $fileName, 'public');
$inputData['profile_picture'] = time() . '_' . $request->profile_pic->getClientOriginalName();
}
$this->employeeRepository->create($inputData);
toastr()->success('Employee Created Succesfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
$this->employeeRepository->create($inputData);
toastr()->success('Employee Created Succesfully');
// } catch (\Throwable $th) {
// toastr()->error($th->getMessage());
// }
return redirect()->route('employee.index');
}
@ -63,8 +75,8 @@ class EmployeeController extends Controller
*/
public function show($id)
{
return view('employee::show');
$data['employee'] = $this->employeeRepository->getEmployeeById($id);
return view('employee::show', $data);
}
/**
@ -82,20 +94,20 @@ class EmployeeController extends Controller
*/
public function update(Request $request, $id): RedirectResponse
{
$inputData = $request->only(['first_name', 'last_name']);
// try {
$inputData = $request->except(['_method', '_token']);
try {
if ($request->hasFile('profile_pic')) {
$fileName = time() . '_' . $request->profile_pic->getClientOriginalName();
$filePath = $request->file('profile_pic')->storeAs('uploads', $fileName, 'public');
$inputData['profile_picture'] = time() . '_' . $request->profile_pic->getClientOriginalName();
if ($request->hasFile('profile_pic')) {
$fileName = time() . '_' . $request->profile_pic->getClientOriginalName();
$filePath = $request->file('profile_pic')->storeAs('uploads', $fileName, 'public');
$inputData['profile_picture'] = time() . '_' . $request->profile_pic->getClientOriginalName();
}
$this->employeeRepository->update($id, $inputData);
toastr()->success('Employee Created Succesfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
$this->employeeRepository->update($id, $inputData);
toastr()->success('Employee Created Succesfully');
// } catch (\Throwable $th) {
// toastr()->error($th->getMessage());
// }
return redirect()->route('employee.index');
}
@ -104,6 +116,41 @@ class EmployeeController extends Controller
*/
public function destroy($id)
{
//
try {
$employeeModel = $this->employeeRepository->getEmployeeById($id);
$employeeModel->user->roles()->detach();
$employeeModel->user->delete();
$employeeModel->delete();
toastr()->success('Employee Delete Succesfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return redirect()->route('employee.index');
}
public function assignRole(Request $request)
{
try {
$employeeModel = $this->employeeRepository->getEmployeeByEmail($request->email);
$inputData = [
'name' => $employeeModel->first_name . ' ' . $employeeModel->last_name,
'email' => $request->email,
'password' => Hash::make('password'),
'email_verified_at' => Carbon::now(),
];
$userModel = $this->userRepository->create($inputData, [$request->role_id]);
$employeeModel->users_id = $userModel->id;
$employeeModel->save();
toastr()->success('Role Assigned Succesfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return redirect()->route('employee.index');
}
}

View File

@ -2,6 +2,7 @@
namespace Modules\Employee\Models;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
class Employee extends Model
@ -10,4 +11,8 @@ class Employee extends Model
protected $primaryKey = 'id';
protected $guarded = [];
public function user()
{
return $this->belongsTo(User::class, 'users_id');
}
}

View File

@ -6,6 +6,7 @@ interface EmployeeInterface
{
public function findAll();
public function getEmployeeById($employeeId);
public function getEmployeeByEmail($email);
public function delete($employeeId);
public function create($EmployeeDetails);
public function update($employeeId, array $newDetails);

View File

@ -8,7 +8,7 @@ class EmployeeRepository implements EmployeeInterface
{
public function findAll()
{
return Employee::paginate(20);
return Employee::with('user.roles')->paginate(20);
}
public function getEmployeeById($employeeId)
@ -16,6 +16,11 @@ class EmployeeRepository implements EmployeeInterface
return Employee::findOrFail($employeeId);
}
public function getEmployeeByEmail($email)
{
return Employee::where('email', $email)->first();
}
public function delete($employeeId)
{
Employee::destroy($employeeId);

View File

@ -17,36 +17,23 @@ return new class extends Migration
$table->string('middle_name')->nullable();
$table->string('last_name')->nullable();
$table->string('email')->nullable();
$table->unsignedBigInteger('genders_id')->nullable();
$table->date('nepali_dob')->nullable();
$table->date('dob')->nullable();
$table->unsignedBigInteger('nationalities_id')->nullable();
$table->text('about_me')->nullable();
$table->string('signature')->nullable();
$table->string('father_name')->nullable();
$table->string('mother_name')->nullable();
$table->string('grand_father_name')->nullable();
$table->string('grand_mother_name')->nullable();
$table->string('spouse')->nullable();
$table->string('contact')->nullable();
$table->string('alt_contact')->nullable();
$table->string('profile_picture')->nullable();
$table->unsignedBigInteger('genders_id')->nullable();
$table->unsignedBigInteger('nationalities_id')->nullable();
$table->unsignedBigInteger('users_id')->nullable();
$table->text('skills')->nullable();
$table->text('experience')->nullable();
$table->integer('is_user_assigned')->nullable()->default(10);
$table->unsignedBigInteger('organization_id')->nullable();
$table->unsignedBigInteger('department_id')->nullable();
$table->unsignedBigInteger('designation_id')->nullable();
$table->text('permanent_address')->nullable();
$table->unsignedBigInteger('permanent_city')->nullable();
$table->text('temporary_address')->nullable();
$table->unsignedBigInteger('temporary_city')->nullable();
$table->text('old_system_address')->nullable();
$table->text('education')->nullable();
$table->unsignedBigInteger('castes_id')->nullable();
$table->unsignedBigInteger('ethnicities_id')->nullable();
$table->unsignedBigInteger('dags_id')->nullable();
$table->string('status')->nullable();
$table->string('status')->nullable()->default(11);
$table->string('remarks')->nullable();
$table->unsignedBigInteger('createdby')->nullable();
$table->unsignedBigInteger('updatedby')->nullable();
$table->timestamps();
});
}

View File

@ -45,8 +45,28 @@
<div class="team-cover"> <img src="assets/images/small/img-9.jpg" alt="" class="img-fluid">
</div>
<div class="card-body p-4">
<div class="ribbon-two ribbon-two-success"><span>Active</span></div>
@if ($employee->user)
<div class="ribbon-two ribbon-two-success">
<span>{{ optional($employee->user)->getRoleNames()->first() }}</span>
</div>
@endif
<div class="row align-items-center team-row">
<div class="col team-settings">
<div class="row">
<div class="col">
</div>
<div class="col dropdown text-end"> <a href="javascript:void(0);" data-bs-toggle="dropdown"
aria-expanded="false" class=""> <i class="ri-more-fill fs-17"></i> </a>
<ul class="dropdown-menu dropdown-menu-end" style="">
<li><a class="dropdown-item remove-item-btn" href="javascript:void(0);"
data-link="{{ route('employee.destroy', $employee->id) }}"
data-id="{{ $employee->id }}"><i
class="ri-delete-bin-5-line text-muted me-2 align-bottom"></i>Delete</a></li>
</ul>
</div>
</div>
</div>
<div class="col-lg-4 col">
<div class="team-profile-img">
<div class="avatar-lg img-thumbnail rounded-circle flex-shrink-0"><img
@ -82,6 +102,7 @@
</li>
<li class="list-inline-item avatar-xs">
<a href="javascript:void(0);" data-bs-toggle="modal" data-bs-target="#assignRoleModal"
data-email="{{ $employee->email }}"
class="avatar-title bg-primary-subtle text-primary fs-15 rounded">
<i class="ri-user-add-line"></i>
</a>
@ -124,29 +145,31 @@
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form action="{{ route('leave.store') }}" class="needs-validation" novalidate method="post">
<div class="row gy-2">
<div class="col-lg-12">
{{ html()->label('Username')->class('form-label') }}
{{ html()->text('username')->class('form-control')->placeholder('Enter Username')->required() }}
</div>
<div class="col-lg-12">
{{ html()->label('Role')->class('form-label') }}
{{ html()->select('role_id', [])->class('form-select')->placeholder('Select Role')->required() }}
</div>
{{ html()->form('POST')->route('employee.assignRole')->class(['needs-validation'])->attributes(['novalidate'])->open() }}
<div class="row gy-2">
<div class="col-lg-12">
{{ html()->label('Email')->class('form-label') }}
{{ html()->email('email')->class('form-control email-field')->placeholder('Enter Email')->isReadonly(true)->required() }}
</div>
<div class="mt-4 text-end">
<button type="submit" class="btn btn-success w-sm">Save</button>
<div class="col-lg-12">
{{ html()->label('Role')->class('form-label') }}
{{ html()->select('role_id', $roleLists)->class('form-select')->placeholder('Select Role')->required() }}
</div>
</form>
</div>
<div class="mt-4 text-end">
<button type="submit" class="btn btn-success w-sm">Save</button>
</div>
{{ html()->form()->close() }}
</div>
</div>
</div>
</div>
<div class="modal fade" id="changePasswordModal" tabindex="-1" aria-labelledby="changePasswordLabel" aria-modal="true">
<div class="modal fade" id="changePasswordModal" tabindex="-1" aria-labelledby="changePasswordLabel"
aria-modal="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header model-primary">
@ -177,3 +200,16 @@
</div>
</div>
@endsection
@push('js')
<script>
$(document).ready(function() {
$('#assignRoleModal').on('shown.bs.modal', function(e) {
// do something...
var email = $(e.relatedTarget).data('email');
$('.email-field').val(email)
console.log(email);
})
})
</script>
@endpush

View File

@ -1,144 +1,121 @@
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-header card-primary">
{{-- <div class="card-header card-primary">
<h4 class="card-title mb-0">Personal Details</h4>
</div>
</div> --}}
<div class="card-body row gy-4">
<div class="card-body">
<div class="row gy-1">
<p class="text-primary">Personal Details</p>
<hr>
<div class="col-md-4">
{{ html()->label('First name')->class('form-label') }}
{{ html()->text('first_name')->class('form-control')->placeholder('Enter First Name')->required() }}
</div>
<div class="col-md-4">
{{ html()->label('First name')->class('form-label') }}
{{ html()->text('first_name')->class('form-control')->placeholder('Enter First Name')->required() }}
</div>
<div class="col-md-4">
{{ html()->label('Middle name')->class('form-label') }}
{{ html()->text('middle_name')->class('form-control')->placeholder('Enter Middle Name') }}
</div>
<div class="col-md-4">
{{ html()->label('Middle name')->class('form-label') }}
{{ html()->text('middle_name')->class('form-control')->placeholder('Enter Middle Name') }}
</div>
<div class="col-md-4">
{{ html()->label('Last name')->class('form-label') }}
{{ html()->text('last_name')->class('form-control')->placeholder('Enter Last Name')->required() }}
{{ html()->div('Please enter last name')->class('invalid-feedback') }}
</div>
<div class="col-md-4">
{{ html()->label('Last name')->class('form-label') }}
{{ html()->text('last_name')->class('form-control')->placeholder('Enter Last Name')->required() }}
{{ html()->div('Please enter last name')->class('invalid-feedback') }}
</div>
<div class="col-md-4">
{{ html()->label('Gender')->class('form-label') }}
{{ html()->select('genders_id', [1 => 'male', 2 => 'female'])->class('form-select')->placeholder('Select Gender') }}
</div>
<div class="col-md-4">
{{ html()->label('Gender')->class('form-label') }}
{{ html()->select('gender', ['male', 'female'])->class('form-select')->placeholder('Select Gender') }}
</div>
<div class="col-md-4">
{{ html()->label('Date of Birth')->class('form-label') }}
{{ html()->date('dob')->class('form-control')->placeholder('Choose Date of Birth')->required() }}
{{ html()->div('Please choose dob')->class('invalid-feedback') }}
<div class="col-md-4">
{{ html()->label('Date of Birth')->class('form-label') }}
{{ html()->date('dob')->class('form-control')->placeholder('Choose Date of Birth')->required() }}
{{ html()->div('Please choose dob')->class('invalid-feedback') }}
</div>
<div class="col-md-4">
{{ html()->label('Nationality')->class('form-label') }}
{{ html()->select('nationalities_id', [1 => 'Nepal', 2 => 'Other'])->class('form-control')->placeholder('Select Nationality') }}
</div>
<div class="col-md-4">
{{ html()->label('Email')->class('form-label') }}
{{ html()->email('email')->class('form-control')->placeholder('Enter Email')->required() }}
{{ html()->div('Please enter email')->class('invalid-feedback') }}
</div>
<div class="col-md-4">
{{ html()->label('Phone Number')->class('form-label') }}
{{ html()->text('contact')->class('form-control')->placeholder('Enter Phone Number') }}
</div>
<div class="col-md-4">
{{ html()->label('Upload Profile Pic')->class('form-label') }}
{{ html()->file('profile_pic')->class('form-control') }}
</div>
</div>
<div class="col-md-4">
{{ html()->label('Nationality')->class('form-label') }}
{{ html()->select('nationality', ['Nepal', 'Other'])->class('form-control')->placeholder('Select Nationality') }}
<div class="row gy-1 mt-1">
<p class="text-primary">Address Details</p>
<hr>
{{-- <div class="col-md-4">
{{ html()->label('Municipality')->class('form-label') }}
{{ html()->select('municipality_id', [])->class('form-select')->placeholder('Select Municipality') }}
</div>
<div class="col-md-4">
{{ html()->label('Ward')->class('form-label') }}
{{ html()->text('ward')->class('form-control')->placeholder('Enter Ward no') }}
</div> --}}
<div class="col-md-4">
{{ html()->label('Permanent Address')->class('form-label') }}
{{ html()->text('permanent_address')->class('form-control')->placeholder('Enter Permanent Address') }}
</div>
<div class="col-md-4">
{{ html()->label('Temporary Address')->class('form-label') }}
{{ html()->text('temporary_address')->class('form-control')->placeholder('Enter Temporary Address') }}
</div>
</div>
<div class="col-md-4">
{{ html()->label('Email')->class('form-label') }}
{{ html()->email('email')->class('form-control')->placeholder('Enter Email')->required() }}
{{ html()->div('Please enter email')->class('invalid-feedback') }}
<div class="row gy-1 mt-1">
<p class="text-primary">Organization Details</p>
<hr>
<div class="col-md-4">
{{ html()->label('Department')->class('form-label') }}
{{ html()->select('department_id', ['Nepal'])->class('form-select')->placeholder('Select Department') }}
</div>
<div class="col-md-4">
{{ html()->label('Designation')->class('form-label') }}
{{ html()->select('designation_id', ['Nepal'])->class('form-select')->placeholder('Select Designation') }}
</div>
{{-- <div class="col-md-4">
{{ html()->label('Join Date')->class('form-label') }}
{{ html()->date('join_date')->class('form-control')->placeholder('Choose Join Date') }}
</div> --}}
<div class="col-md-8">
{{ html()->label('Remarks')->class('form-label') }}
{{ html()->textarea('remarks')->class('form-control')->placeholder('Enter Remarks') }}
</div>
</div>
<div class="col-md-4">
{{ html()->label('Phone Number')->class('form-label') }}
{{ html()->text('phone')->class('form-control')->placeholder('Enter Phone Number') }}
</div>
<div class="col-md-4">
{{ html()->label('Upload Profile Pic')->class('form-label') }}
{{ html()->file('profile_pic')->class('form-control') }}
</div>
</div>
<!-- end card body -->
</div>
<!-- end card -->
<div class="card">
<div class="card-header card-primary">
<h5 class="card-title mb-0">Address Detail</h5>
</div>
<div class="card-body row gy-2">
{{-- <div class="col-md-4">
{{ html()->label('Country')->class('form-label') }}
{{ html()->select('country_id', ['Nepal'])->class('form-select')->placeholder('Select Country') }}
</div> --}}
<div class="col-md-4">
{{ html()->label('State')->class('form-label') }}
{{ html()->select('state_id', ['Nepal'])->class('form-select')->placeholder('Select State') }}
</div>
<div class="col-md-4">
{{ html()->label('District name')->class('form-label') }}
{{ html()->select('district_id', [])->class('form-select')->placeholder('Select District') }}
</div>
<div class="col-md-4">
{{ html()->label('City')->class('form-label') }}
{{ html()->text('last_name')->class('form-control')->placeholder('Enter City Name') }}
</div>
<div class="col-md-4">
{{ html()->label('municipality')->class('form-label') }}
{{ html()->select('municipality_id', [])->class('form-select')->placeholder('Select Municipality') }}
</div>
<div class="col-md-4">
{{ html()->label('Ward')->class('form-label') }}
{{ html()->text('ward')->class('form-control')->placeholder('Enter Ward no') }}
</div>
<div class="col-md-4">
{{ html()->label('Permanent Address')->class('form-label') }}
{{ html()->text('perm_address')->class('form-control')->placeholder('Enter Permanent Address') }}
</div>
<div class="col-md-4">
{{ html()->label('Temporary Address')->class('form-label') }}
{{ html()->text('temp_address')->class('form-control')->placeholder('Enter Temporary Address') }}
</div>
</div>
</div>
<div class="card">
<div class="card-header card-primary">
<h5 class="card-title mb-0">Organization Detail</h5>
</div>
<div class="card-body row gy-2">
<div class="col-md-4">
{{ html()->label('Department')->class('form-label') }}
{{ html()->select('department_id', ['Nepal'])->class('form-select')->placeholder('Select Department') }}
</div>
<div class="col-md-4">
{{ html()->label('Designation')->class('form-label') }}
{{ html()->select('designation_id', ['Nepal'])->class('form-select')->placeholder('Select Designation') }}
</div>
<div class="col-md-4">
{{ html()->label('Join Date')->class('form-label') }}
{{ html()->date('join_date')->class('form-control')->placeholder('Choose Join Date') }}
</div>
<div class="col-md-8">
{{ html()->label('Remarks')->class('form-label') }}
{{ html()->textarea('remark')->class('form-control')->placeholder('Enter Remarks') }}
</div>
</div>
</div>
<!-- end card -->
<div class="mb-4 text-end">
<button type="submit" class="btn btn-success w-sm">Save</button>
</div>

View File

@ -0,0 +1,128 @@
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-header card-primary">
<h4 class="card-title mb-0">Personal Details</h4>
</div>
<div class="card-body row gy-4">
<div class="col-md-4">
{{ html()->label('First name')->class('form-label') }}
{{ html()->text('first_name')->class('form-control')->placeholder('Enter First Name')->required() }}
</div>
<div class="col-md-4">
{{ html()->label('Middle name')->class('form-label') }}
{{ html()->text('middle_name')->class('form-control')->placeholder('Enter Middle Name') }}
</div>
<div class="col-md-4">
{{ html()->label('Last name')->class('form-label') }}
{{ html()->text('last_name')->class('form-control')->placeholder('Enter Last Name')->required() }}
{{ html()->div('Please enter last name')->class('invalid-feedback') }}
</div>
<div class="col-md-4">
{{ html()->label('Gender')->class('form-label') }}
{{ html()->select('gender', ['male', 'female'])->class('form-select')->placeholder('Select Gender') }}
</div>
<div class="col-md-4">
{{ html()->label('Date of Birth')->class('form-label') }}
{{ html()->date('dob')->class('form-control')->placeholder('Choose Date of Birth')->required() }}
{{ html()->div('Please choose dob')->class('invalid-feedback') }}
</div>
<div class="col-md-4">
{{ html()->label('Nationality')->class('form-label') }}
{{ html()->select('nationality', ['Nepal', 'Other'])->class('form-control')->placeholder('Select Nationality') }}
</div>
<div class="col-md-4">
{{ html()->label('Email')->class('form-label') }}
{{ html()->email('email')->class('form-control')->placeholder('Enter Email')->required() }}
{{ html()->div('Please enter email')->class('invalid-feedback') }}
</div>
<div class="col-md-4">
{{ html()->label('Phone Number')->class('form-label') }}
{{ html()->text('phone')->class('form-control')->placeholder('Enter Phone Number') }}
</div>
<div class="col-md-4">
{{ html()->label('Upload Profile Pic')->class('form-label') }}
{{ html()->file('profile_pic')->class('form-control') }}
</div>
</div>
<!-- end card body -->
</div>
<!-- end card -->
<div class="card">
<div class="card-header card-primary">
<h5 class="card-title mb-0">Address Detail</h5>
</div>
<div class="card-body row gy-2">
<div class="col-md-4">
{{ html()->label('Municipality')->class('form-label') }}
{{ html()->select('municipality_id', [])->class('form-select')->placeholder('Select Municipality') }}
</div>
<div class="col-md-4">
{{ html()->label('Ward')->class('form-label') }}
{{ html()->text('ward')->class('form-control')->placeholder('Enter Ward no') }}
</div>
<div class="col-md-4">
{{ html()->label('Permanent Address')->class('form-label') }}
{{ html()->text('perm_address')->class('form-control')->placeholder('Enter Permanent Address') }}
</div>
<div class="col-md-4">
{{ html()->label('Temporary Address')->class('form-label') }}
{{ html()->text('temp_address')->class('form-control')->placeholder('Enter Temporary Address') }}
</div>
</div>
</div>
<div class="card">
<div class="card-header card-primary">
<h5 class="card-title mb-0">Organization Detail</h5>
</div>
<div class="card-body row gy-2">
<div class="col-md-4">
{{ html()->label('Department')->class('form-label') }}
{{ html()->select('department_id', ['Nepal'])->class('form-select')->placeholder('Select Department') }}
</div>
<div class="col-md-4">
{{ html()->label('Designation')->class('form-label') }}
{{ html()->select('designation_id', ['Nepal'])->class('form-select')->placeholder('Select Designation') }}
</div>
<div class="col-md-4">
{{ html()->label('Join Date')->class('form-label') }}
{{ html()->date('join_date')->class('form-control')->placeholder('Choose Join Date') }}
</div>
<div class="col-md-8">
{{ html()->label('Remarks')->class('form-label') }}
{{ html()->textarea('remark')->class('form-control')->placeholder('Enter Remarks') }}
</div>
</div>
</div>
<!-- end card -->
<div class="mb-4 text-end">
<button type="submit" class="btn btn-success w-sm">Save</button>
</div>
</div>
</div>

View File

@ -12,8 +12,12 @@ use Modules\Employee\Http\Controllers\EmployeeController;
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
*/
Route::group([], function () {
Route::group(['middleware' => 'auth'], function () {
Route::post('assignRole', [EmployeeController::class, 'assignRole'])->name('employee.assignRole');
Route::resource('employee', EmployeeController::class)->names('employee');
Route::group(['prefix' => 'employee'], function () {
});
});

View File

@ -24,7 +24,8 @@ class UserRepository implements UserInterface
public function create(array $userDetails, array $role)
{
$user = User::create($userDetails);
return $user->roles()->attach($role);
$user->roles()->attach($role);
return $user;
}
public function update($userId, array $newDetails)

View File

@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use Modules\Employee\Models\Employee;
use Spatie\Permission\Traits\HasRoles;
class User extends Authenticatable
@ -45,7 +46,8 @@ class User extends Authenticatable
'email_verified_at' => 'datetime',
];
// public function employee(){
// return $this->belongsTo(Employee::class,'employee_id');
// }
public function employee()
{
return $this->hasOne(Employee::class, 'users_id');
}
}

View File

@ -0,0 +1,33 @@
<?php
namespace Modules\Department\Repositories;
use Modules\Department\Models\Department;
class DepartmentService
{
public function findAll()
{
return Department::paginate(20);
}
public function getDepartmentById($DepartmentId)
{
return Department::findOrFail($DepartmentId);
}
public function delete($DepartmentId)
{
Department::destroy($DepartmentId);
}
public function create($DepartmentDetails)
{
return Department::create($DepartmentDetails);
}
public function update($DepartmentId, array $newDetails)
{
return Department::whereId($DepartmentId)->update($newDetails);
}
}

View File

@ -1,7 +1,7 @@
$('body').on('click', '.remove-item-btn', function (e) {
e.preventDefault();
let url = $(this).data('href');
let url = $(this).data('link');
let id = $(this).data('id');
Swal.fire({