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

110 lines
2.7 KiB
PHP
Raw Normal View History

<?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\TransferRepository;
class TransferController extends Controller
{
private $transferRepository;
public function __construct(TransferRepository $transferRepository)
{
$this->transferRepository = $transferRepository;
}
/**
* Display a listing of the resource.
*/
public function index()
{
$data['title'] = 'Transfer Lists';
$data['transferLists'] = $this->transferRepository->findAll();
return view('admin::transfers.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['title'] = 'Create Transfers';
$data['editable'] = false;
return view('admin::transfers.create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
try {
$this->transferRepository->create($request->all());
toastr()->success('Transfer Created Successfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return redirect()->route('transfer.index');
}
/**
* Show the specified resource.
*/
public function show($id)
{
return view('admin::transfers.show');
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
try {
$data['title'] = 'Edit Transfers';
$data['editable'] = true;
$data['transfer'] = $this->transferRepository->getTransferById($id);
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return view('admin::transfers.edit', $data);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
try {
$this->transferRepository->update($id, $request->all());
toastr()->success('Transfer Updated Successfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return redirect()->route('transfer.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
try {
$this->transferRepository->delete($id);
toastr()->success('Transfer Deleted Successfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return redirect()->route('transfer.index');
}
}