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

110 lines
2.7 KiB
PHP

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