Merge branch 'omis_dharma' of ssh://bibgit.com:22022/dharmaraj/New-OMIS
This commit is contained in:
@ -3,13 +3,15 @@
|
||||
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 Illuminate\Support\Facades\Storage;
|
||||
use Modules\Admin\Services\AdminService;
|
||||
use Modules\Employee\Repositories\EmployeeInterface;
|
||||
use Modules\User\Repositories\UserInterface;
|
||||
use Spatie\Permission\Models\Role;
|
||||
|
||||
class EmployeeController extends Controller
|
||||
{
|
||||
@ -17,10 +19,13 @@ class EmployeeController extends Controller
|
||||
private $employeeRepository;
|
||||
private $userRepository;
|
||||
|
||||
public function __construct(EmployeeInterface $employeeRepository, UserInterface $userRepository)
|
||||
private $adminService;
|
||||
|
||||
public function __construct(EmployeeInterface $employeeRepository, UserInterface $userRepository, AdminService $adminService)
|
||||
{
|
||||
$this->employeeRepository = $employeeRepository;
|
||||
$this->userRepository = $userRepository;
|
||||
$this->adminService = $adminService;
|
||||
|
||||
}
|
||||
/**
|
||||
@ -42,8 +47,10 @@ class EmployeeController extends Controller
|
||||
$data['title'] = 'Create Employee';
|
||||
$data['departmentList'] = [];
|
||||
$data['designationList'] = [];
|
||||
$data['genderList'] = [];
|
||||
$data['nationalityList'] = [];
|
||||
$data['nationalityList'] = $this->adminService->pluckNationalities();
|
||||
$data['genderList'] = $this->adminService->pluckGenders();
|
||||
$data['casteList'] = $this->adminService->pluckCastes();
|
||||
$data['cityList'] = $this->adminService->pluckCities();
|
||||
|
||||
return view('employee::create', $data);
|
||||
}
|
||||
@ -56,15 +63,19 @@ class EmployeeController extends Controller
|
||||
$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();
|
||||
if ($request->hasFile('profile_picture')) {
|
||||
$image = $request->profile_picture;
|
||||
$fileName = time() . '_' . $image->getClientOriginalName();
|
||||
$filePath = Storage::disk('public')->putFileAs('uploads', $image, $fileName);
|
||||
$inputData['profile_picture'] = 'storage/' . $filePath;
|
||||
}
|
||||
|
||||
$this->employeeRepository->create($inputData);
|
||||
|
||||
toastr()->success('Employee Created Succesfully');
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
echo $th->getMessage();
|
||||
toastr()->error($th->getMessage());
|
||||
}
|
||||
return redirect()->route('employee.index');
|
||||
@ -95,17 +106,22 @@ class EmployeeController extends Controller
|
||||
public function update(Request $request, $id): RedirectResponse
|
||||
{
|
||||
$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_picture')) {
|
||||
$image = $request->profile_picture;
|
||||
$fileName = time() . '_' . $image->getClientOriginalName();
|
||||
$filePath = Storage::disk('public')->putFileAs('uploads', $image, $fileName);
|
||||
$inputData['profile_picture'] = 'storage/' . $filePath;
|
||||
}
|
||||
|
||||
$this->employeeRepository->update($id, $inputData);
|
||||
|
||||
toastr()->success('Employee Created Succesfully');
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
|
||||
toastr()->error($th->getMessage());
|
||||
}
|
||||
return redirect()->route('employee.index');
|
||||
@ -114,19 +130,25 @@ class EmployeeController extends Controller
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy($id)
|
||||
public function destroy(Request $request)
|
||||
{
|
||||
try {
|
||||
$employeeModel = $this->employeeRepository->getEmployeeById($id);
|
||||
$employeeModel->user->roles()->detach();
|
||||
$employeeModel->user->delete();
|
||||
$employeeModel->delete();
|
||||
|
||||
$employeeModel = $this->employeeRepository->getEmployeeById($request->id);
|
||||
|
||||
optional($employeeModel)->user?->roles()?->detach();
|
||||
|
||||
optional($employeeModel)->user?->delete();
|
||||
|
||||
optional($employeeModel)->delete();
|
||||
|
||||
toastr()->success('Employee Delete Succesfully');
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
toastr()->error($th->getMessage());
|
||||
}
|
||||
return redirect()->route('employee.index');
|
||||
|
||||
return response()->json(['status' => true, 'message' => 'Employee Delete Succesfully']);
|
||||
|
||||
}
|
||||
|
||||
@ -153,4 +175,14 @@ class EmployeeController extends Controller
|
||||
return redirect()->route('employee.index');
|
||||
}
|
||||
|
||||
public function changePassword(Request $request)
|
||||
{
|
||||
dd($request->all());
|
||||
try {
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
toastr()->error($th->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -42,7 +42,8 @@
|
||||
@forelse ($employees as $employee)
|
||||
<div class="col">
|
||||
<div class="card team-box ribbon-box mb-lg-0 material-shadow border shadow-none">
|
||||
<div class="team-cover"> <img src="assets/images/small/img-9.jpg" alt="" class="img-fluid">
|
||||
<div class="team-cover">
|
||||
<img src="{{ asset('assets/images/small/img-9.jpg') }}" alt="" class="img-fluid">
|
||||
</div>
|
||||
<div class="card-body p-4">
|
||||
@if ($employee->user)
|
||||
@ -69,9 +70,11 @@
|
||||
|
||||
<div class="col-lg-4 col">
|
||||
<div class="team-profile-img">
|
||||
<div class="avatar-lg img-thumbnail rounded-circle flex-shrink-0"><img
|
||||
src="{{ asset('app/public/uploads/' . $employee->profile_picture) }}" alt=""
|
||||
class="member-img img-fluid d-block rounded-circle"></div>
|
||||
<div class="img-thumbnail rounded-circle flex-shrink-0">
|
||||
<img style="height: 90px; width:90px; object-fit:cover"
|
||||
src="{{ asset($employee->profile_picture) }}" alt=""
|
||||
class="img-fluid rounded-circle">
|
||||
</div>
|
||||
<div class="team-content"> <a class="member-name"
|
||||
href="{{ route('employee.show', $employee->id) }}">
|
||||
<h5 class="fs-16 mb-1">{{ $employee->first_name }}</h5>
|
||||
|
@ -54,8 +54,8 @@
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
{{ html()->label('Upload Profile Pic')->class('form-label') }}
|
||||
{{ html()->file('profile_pic')->class('form-control') }}
|
||||
{{ html()->label('Upload Profile Picture')->class('form-label') }}
|
||||
{{ html()->file('profile_picture')->class('form-control') }}
|
||||
|
||||
</div>
|
||||
|
||||
|
@ -14,12 +14,16 @@ use Modules\Employee\Http\Controllers\EmployeeController;
|
||||
|
|
||||
*/
|
||||
|
||||
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 () {
|
||||
});
|
||||
Route::middleware('auth')->group(
|
||||
function () {
|
||||
|
||||
});
|
||||
Route::prefix('employee')->as('employee.')->group(function () {
|
||||
|
||||
Route::post('assignRole', [EmployeeController::class, 'assignRole'])->name('assignRole');
|
||||
Route::post('changePassword', [EmployeeController::class, 'changePassword'])->name('assignRole');
|
||||
});
|
||||
|
||||
Route::resource('employee', EmployeeController::class)->names('employee');
|
||||
|
||||
}
|
||||
);
|
||||
|
Reference in New Issue
Block a user