StocksNew/Modules/PMS/app/Http/Controllers/ClientController.php

122 lines
3.6 KiB
PHP
Raw Normal View History

2024-08-27 17:48:06 +05:45
<?php
namespace Modules\PMS\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Modules\Admin\Repositories\CountryRepository;
use Modules\Admin\Repositories\FieldRepository;
use Modules\PMS\Models\Client;
use Modules\PMS\Repositories\ClientInterface;
class ClientController extends Controller
{
private $clientRepository;
private $fieldRepository;
private $countryRepository;
public function __construct(ClientInterface $clientRepository, FieldRepository $fieldRepository, CountryRepository $countryRepository)
{
$this->clientRepository = $clientRepository;
$this->fieldRepository = $fieldRepository;
$this->countryRepository = $countryRepository;
}
/**
* Display a listing of the resource.
*/
public function index()
{
$data['title'] = 'Client List';
$data['clients'] = $this->clientRepository->findAll();
return view('pms::client.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['title'] = 'Create Client';
$data['status'] = Client::STATUS;
$data['editable'] = false;
$data['genderList'] = $this->fieldRepository->getDropdownByAlias('gender');
$data['salutationList'] = $this->fieldRepository->getDropdownByAlias('salutation');
$data['countryList'] = $this->countryRepository->pluck();
return view('pms::client.create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
$inputData = $request->all();
try {
$this->clientRepository->create($inputData);
toastr()->success('Client Created Succesfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return redirect()->route('client.index');
}
/**
* Show the specified resource.
*/
public function show($id)
{
$data['title'] = 'View Client';
$data['status'] = Client::STATUS;
$data['client'] = $this->clientRepository->getClientById($id);
return view('pms::client.show', $data);
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$data['title'] = 'Edit Client';
$data['status'] = Client::STATUS;
$data['editable'] = true;
$data['client'] = $this->clientRepository->getClientById($id);
$data['genderList'] = $this->fieldRepository->getDropdownByAlias('gender');
$data['salutationList'] = $this->fieldRepository->getDropdownByAlias('salutation');
$data['countryList'] = $this->countryRepository->pluck();
return view('pms::client.edit', $data);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
$inputData = $request->except(['_method', '_token']);
try {
$this->clientRepository->update($id, $inputData);
toastr()->success('Client Update Succesfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return redirect()->route('client.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
try {
$this->clientRepository->delete($id);
toastr()->success('Client Deleted Succesfully');
} catch (\Throwable $th) {
//throw $th;
toastr()->error($th->getMessage());
}
}
}