firstcommit
This commit is contained in:
@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Billing\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Billing\Repositories\BillingComponentInterface;
|
||||
use Modules\Admin\Repositories\FieldInterface;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class BillingComponentController extends Controller
|
||||
{
|
||||
private $fieldRepository;
|
||||
private $billingComponentRepository;
|
||||
|
||||
public function __construct(
|
||||
FieldInterface $fieldRepository,
|
||||
BillingComponentInterface $billingComponentRepository
|
||||
) {
|
||||
$this->fieldRepository = $fieldRepository;
|
||||
$this->billingComponentRepository = $billingComponentRepository;
|
||||
}
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$data['title'] = 'Billing Component List';
|
||||
|
||||
$data['billingComponentList'] = $this->billingComponentRepository->findAll();
|
||||
|
||||
return view('billing::billingComponent.index', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$data['title'] = 'Create Billing Component';
|
||||
$data['editable'] = false;
|
||||
return view('billing::billingComponent.create', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->mergeIfMissing([
|
||||
'alias' => Str::slug($request->title),
|
||||
]);
|
||||
try {
|
||||
$this->billingComponentRepository->create($request->all());
|
||||
|
||||
toastr()->success('BillingComponent Created Succesfully');
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
|
||||
toastr()->error($th->getMessage());
|
||||
|
||||
}
|
||||
return redirect()->route('billingComponent.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
return view('billing::billingComponent.show');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$data['title'] = 'Edit Billing Component';
|
||||
$data['editable'] = true;
|
||||
$data['billingComponent'] = $this->billingComponentRepository->getBillingComponentById($id);
|
||||
return view('billing::billingComponent.edit', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, $id): RedirectResponse
|
||||
{
|
||||
|
||||
$request->mergeIfMissing([
|
||||
'alias' => Str::slug($request->title),
|
||||
]);
|
||||
|
||||
$inputData = $request->except(['_method', '_token']);
|
||||
|
||||
try {
|
||||
$this->billingComponentRepository->update($id, $inputData);
|
||||
|
||||
toastr()->success('BillingComponent Update Succesfully');
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
|
||||
toastr()->error($th->getMessage());
|
||||
|
||||
}
|
||||
return redirect()->route('billingComponent.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
try {
|
||||
$this->billingComponentRepository->delete($id);
|
||||
|
||||
toastr()->success('BillingComponent Deleted Succesfully');
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
|
||||
toastr()->error($th->getMessage());
|
||||
|
||||
}
|
||||
return response()->json([
|
||||
|
||||
'status' => true,
|
||||
|
||||
]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user