StocksNew/Modules/Training/app/Http/Controllers/TrainingListController.php
Sampanna Rimal 53c0140f58 first commit
2024-08-27 17:48:06 +05:45

115 lines
3.3 KiB
PHP

<?php
namespace Modules\Training\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Modules\Admin\Repositories\DepartmentRepository;
use Modules\Employee\Repositories\EmployeeRepository;
use Modules\Training\Repositories\TrainerRepository;
use Modules\Training\Repositories\TrainingListRepository;
class TrainingListController extends Controller
{
private $trainingListRepository;
private $employeeRepository;
private $trainerRepository;
private $departmentRepository;
public function __construct(TrainingListRepository $trainingListRepository,
EmployeeRepository $employeeRepository,
TrainerRepository $trainerRepository,
DepartmentRepository $departmentRepository )
{
$this->trainingListRepository = $trainingListRepository;
$this->employeeRepository = $employeeRepository;
$this->trainerRepository = $trainerRepository;
$this->departmentRepository = $departmentRepository;
}
/**
* Display a listing of the resource.
*/
public function index()
{
$data['title'] = 'Training Lists';
$data['trainingLists'] = $this->trainingListRepository->findAll();
return view('training::training-list.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['title'] = 'Create Training List';
$data['editable'] = false;
$data['employee'] = $this->employeeRepository->pluck();
$data['trainer'] = $this->trainerRepository->pluck();
$data['department'] = $this->departmentRepository->pluck();
return view('training::training-list.create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
$this->trainingListRepository->create($request->all());
toastr()->success('Training List Created Successfully');
return redirect()->route('trainingList.index');
}
/**
* Show the specified resource.
*/
public function show($id)
{
$data['title'] = 'Training Details';
$data['item'] = $this->trainingListRepository->getTrainingListById($id);
return view('training::training-list.show', $data);
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$data['editable'] = true;
$data['trainingList'] = $this->trainingListRepository->getTrainingListById($id);
return view('training::training-list.edit', $data);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
$inputData = $request->all();
$this->trainingListRepository->update($id, $inputData);
toastr()->success('Training List Updated Succesfully');
return redirect()->route('trading-list.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
$this->trainingListRepository->delete($id);
toastr()->success('Training List Deleted Succesfully');
}
}