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

108 lines
2.7 KiB
PHP

<?php
namespace Modules\Office\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Modules\Office\Repositories\DepositInterface;
use Modules\Office\Repositories\DepositRepository;
class DepositController extends Controller
{
private $depositRepository;
public function __construct(DepositInterface $depositRepository)
{
$this->depositRepository = $depositRepository;
}
/**
* Display a listing of the resource.
*/
public function index()
{
$data['title'] = "Deposit Lists";
$data['depositLists'] = $this->depositRepository->findAll();
return view('office::deposits.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['title'] = "Create Deposit";
$data['editable'] = false;
return view('office::deposits.create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
try {
$this->depositRepository->create($request->all());
toastr()->success('Deposit Created Successfully.');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return redirect()->route('deposit.index');
}
/**
* Show the specified resource.
*/
public function show($id)
{
return view('office::deposits.show');
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$data['title'] = "Edit Deposit";
$data['editable'] = true;
$data['deposit'] = $this->depositRepository->getDepositById($id);
return view('office::deposits.edit', $data);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
try {
$this->depositRepository->update($id, $request->except(['_token', '_method']));
toastr()->success('Deposit Updated Successfully.');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
// return redirect()->route('deposit.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
try {
$this->depositRepository->delete($id);
toastr()->success('Deposit deleted successfully.');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return redirect()->route('deposit.index');
}
}