admin module
This commit is contained in:
@ -7,6 +7,8 @@ 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;
|
||||
@ -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);
|
||||
}
|
||||
@ -53,14 +60,14 @@ class EmployeeController extends Controller
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
dd($request->all());
|
||||
$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);
|
||||
@ -99,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');
|
||||
|
Reference in New Issue
Block a user