StocksNew/Modules/Office/app/Http/Controllers/GeneratorLogBookController.php

113 lines
3.2 KiB
PHP
Raw Normal View History

2024-08-27 12:03:06 +00:00
<?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\GeneratorLogBookInterface;
use Modules\Office\Repositories\GeneratorLogBookRepository;
use Modules\Office\Repositories\GeneratorRepository;
class GeneratorLogBookController extends Controller
{
private $generatorLogBookRepository;
private $generatorRepository;
public function __construct(GeneratorLogBookInterface $generatorLogBookRepository,GeneratorLogBookInterface $generatorRepository)
{
$this->generatorLogBookRepository = $generatorLogBookRepository;
$this->generatorRepository = $generatorRepository;
}
/**
* Display a listing of the resource.
*/
public function index()
{
$data['title'] = "GeneratorLogBook Lists";
$data['generatorLogBookLists'] = $this->generatorLogBookRepository->findAll();
return view('office::generatorlogbooks.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['title'] = "Create GeneratorLogBook";
$data['editable'] = false;
$data['generatorLists'] = $this->generatorRepository->pluck();
return view('office::generatorlogbooks.create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
try {
$this->generatorLogBookRepository->create($request->all());
toastr()->success('GeneratorLogBook Created Successfully.');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return redirect()->route('generatorLogBook.index');
}
/**
* Show the specified resource.
*/
public function show($id)
{
return view('office::generatorlogbooks.show');
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$data['title'] = "Edit GeneratorLogBook";
$data['editable'] = true;
$data['generatorLogBook'] = $this->generatorLogBookRepository->getGeneratorLogBookById($id);
$data['generatorLists'] = $this->generatorRepository->pluck();
return view('office::generatorlogbooks.edit', $data);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
try {
$this->generatorLogBookRepository->update($id, $request->all());
toastr()->success('GeneratorLogBook Updated Successfully.');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return redirect()->route('generatorLogBook.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
try {
$this->generatorLogBookRepository->delete($id);
toastr()->success('GeneratorLogBook deleted successfully.');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return redirect()->route('generatorLogBook.index');
}
}