New-OMIS/Modules/Admin/app/Http/Controllers/CompanyTypeController.php

110 lines
2.8 KiB
PHP

<?php
namespace Modules\Admin\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Modules\Admin\Repositories\CompanyTypeRepository;
class CompanyTypeController extends Controller
{
private $companyTypeRepository;
public function __construct(CompanyTypeRepository $companyTypeRepository)
{
$this->companyTypeRepository = $companyTypeRepository;
}
/**
* Display a listing of the resource.
*/
public function index()
{
$data['title'] = 'Company Type Lists';
$data['companyTypeLists'] = $this->companyTypeRepository->findAll();
return view('admin::companytypes.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['title'] = 'Create Company Type';
$data['editable'] = false;
return view('admin::companytypes.create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
try {
$this->companyTypeRepository->create($request->all());
toastr()->success('Company Type Created Successfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return redirect()->route('companyType.index');
}
/**
* Show the specified resource.
*/
public function show($id)
{
return view('admin::companytypes.show');
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
try {
$data['title'] = 'Edit Company Type';
$data['editable'] = true;
$data['companyType'] = $this->companyTypeRepository->getCompanyById($id);
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return view('admin::companytypes.edit', $data);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
try {
$this->companyTypeRepository->update($id, $request->all());
toastr()->success('Company Updated Successfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return redirect()->route('company.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
try {
$this->companyTypeRepository->delete($id);
toastr()->success('Company Type Deleted Successfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return redirect()->route('companyType.index');
}
}