136 lines
3.4 KiB
PHP
136 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace Modules\Customer\Http\Controllers;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Flasher\Prime\FlasherInterface;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Modules\Admin\Repositories\FieldInterface;
|
|
use Modules\Admin\Services\AdminService;
|
|
use Modules\Customer\Repositories\CustomerInterface;
|
|
use Modules\User\Repositories\UserInterface;
|
|
|
|
class CustomerController extends Controller
|
|
{
|
|
private $userRepository;
|
|
private $customerRepository;
|
|
|
|
private $fieldRepository;
|
|
|
|
public function __construct(
|
|
FieldInterface $fieldRepository,
|
|
UserInterface $userRepository,
|
|
CustomerInterface $customerRepository
|
|
) {
|
|
$this->userRepository = $userRepository;
|
|
$this->fieldRepository = $fieldRepository;
|
|
$this->customerRepository = $customerRepository;
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index()
|
|
{
|
|
$data['title'] = 'Customer List';
|
|
$data['customers'] = $this->customerRepository->findAll();
|
|
return view('customer::customer.index', $data);
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*/
|
|
public function create()
|
|
{
|
|
$data['title'] = 'Create Customer';
|
|
$data['editable'] = false;
|
|
toastr()->success('Hello');
|
|
|
|
return view('customer::customer.create', $data);
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
|
|
|
|
try {
|
|
|
|
$inputData = $request->all();
|
|
|
|
$this->customerRepository->create($inputData);
|
|
|
|
} catch (\Throwable $th) {
|
|
|
|
toastr()->error($th->getMessage());
|
|
}
|
|
|
|
toastr()->success('Hello');
|
|
return redirect()->route('customer.index');
|
|
}
|
|
|
|
/**
|
|
* Show the specified resource.
|
|
*/
|
|
public function show($id)
|
|
{
|
|
$data['title'] = 'Show Customer';
|
|
$data['customer'] = $this->customerRepository->getCustomerById($id);
|
|
return view('customer::customer.show', $data);
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
$data['title'] = 'Edit Customer';
|
|
$data['editable'] = true;
|
|
$data['customer'] = $this->customerRepository->getCustomerById($id);
|
|
return view('customer::customer.edit', $data);
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(Request $request, $id): RedirectResponse
|
|
{
|
|
$inputData = $request->except(['_method', '_token']);
|
|
try {
|
|
|
|
$this->customerRepository->update($id, $inputData);
|
|
|
|
flash()->success('Customer updated succesfully');
|
|
|
|
} catch (\Throwable $th) {
|
|
|
|
flash()->error($th->getMessage());
|
|
}
|
|
return redirect()->route('customer.index');
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy($id)
|
|
{
|
|
try {
|
|
$CustomerModel = $this->customerRepository->getCustomerById($id);
|
|
|
|
$CustomerModel->delete();
|
|
|
|
flash()->success('Customer deleted succesfully');
|
|
|
|
} catch (\Throwable $th) {
|
|
|
|
flash()->error($th->getMessage());
|
|
}
|
|
|
|
return response()->json(['status' => true, 'message' => 'Customer deleted succesfully']);
|
|
|
|
}
|
|
}
|