Attendance module
This commit is contained in:
@ -6,15 +6,24 @@ use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Modules\Attendance\Repositories\AttendanceRepository;
|
||||
|
||||
class AttendanceController extends Controller
|
||||
{
|
||||
private $attendanceRepository;
|
||||
|
||||
public function __construct(AttendanceRepository $attendanceRepository)
|
||||
{
|
||||
$this->attendanceRepository = $attendanceRepository;
|
||||
}
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('attendance::index');
|
||||
$data['title'] = 'Attendance Lists';
|
||||
$data['attendanceLists'] = $this->attendanceRepository->findAll();
|
||||
return view('attendance::attendances.index', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -22,7 +31,9 @@ class AttendanceController extends Controller
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('attendance::create');
|
||||
$data['title'] = 'Create Attendance';
|
||||
$data['editable'] = false;
|
||||
return view('attendance::attendances.create', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -30,7 +41,17 @@ class AttendanceController extends Controller
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
//
|
||||
$request->merge([
|
||||
'date' => $request->date ? $request->date : now()->format('Y-m-d'),
|
||||
]);
|
||||
|
||||
try {
|
||||
$this->attendanceRepository->create($request->all());
|
||||
toastr()->success('Attendance Created Successfully');
|
||||
} catch (\Throwable $th) {
|
||||
toastr()->error($th->getMessage());
|
||||
}
|
||||
return redirect()->route('attendance.index');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -38,7 +59,7 @@ class AttendanceController extends Controller
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
return view('attendance::show');
|
||||
return view('attendance::attendances.show');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -46,7 +67,17 @@ class AttendanceController extends Controller
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
return view('attendance::edit');
|
||||
try {
|
||||
$data['title'] = 'Edit Attendance';
|
||||
$data['editable'] = true;
|
||||
$data['attendance'] = $this->attendanceRepository->getAttendanceById($id);
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
toastr()->error($th->getMessage());
|
||||
}
|
||||
|
||||
return view('attendance::attendances.edit', $data);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -54,7 +85,15 @@ class AttendanceController extends Controller
|
||||
*/
|
||||
public function update(Request $request, $id): RedirectResponse
|
||||
{
|
||||
//
|
||||
try {
|
||||
|
||||
$this->attendanceRepository->update($id, $request->all());
|
||||
toastr()->success('Attendance Updated Successfully');
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
toastr()->error($th->getMessage());
|
||||
}
|
||||
return redirect()->route('attendance.index');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -62,6 +101,12 @@ class AttendanceController extends Controller
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
try {
|
||||
$this->attendanceRepository->delete($id);
|
||||
toastr()->success('Attendance Deleted Successfully');
|
||||
} catch (\Throwable $th) {
|
||||
toastr()->error($th->getMessage());
|
||||
}
|
||||
return redirect()->route('attendance.index');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user