58 lines
1.6 KiB
PHP
58 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Setting;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\ReferenceAr;
|
|
use App\Models\ReferenceGhg;
|
|
use App\Services\Setting\GwpService;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Routing\Controllers\HasMiddleware;
|
|
use Illuminate\Routing\Controllers\Middleware;
|
|
|
|
class GwpController implements HasMiddleware
|
|
{
|
|
protected $title = 'GWP';
|
|
protected $template = 'modules.setting.gwp';
|
|
protected $route = 'modules.pengaturan.gwp';
|
|
protected $gwpService;
|
|
|
|
public function __construct(GwpService $gwpService)
|
|
{
|
|
$this->gwpService = $gwpService;
|
|
}
|
|
|
|
public static function middleware(): array
|
|
{
|
|
return [
|
|
//new Middleware('permission:/setting/gwp'),
|
|
];
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$data['ghgs'] = ReferenceGhg::rowActive()->orderByRowNum()->get();
|
|
$data['ars'] = ReferenceAr::rowActive()->orderByRowNum()->get();
|
|
$data['gwpMatrix'] = $this->gwpService->getMatrix();
|
|
$data['route'] = $this->route;
|
|
$data['title'] = $this->title;
|
|
|
|
return view($this->template.'.index',$data);
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
$request->validate([
|
|
'gwp' => 'required|array',
|
|
]);
|
|
|
|
try {
|
|
$this->gwpService->save($request->all());
|
|
|
|
return redirect()->route($this->route.'.index')->with('success', 'GWP berhasil disimpan.');
|
|
} catch (\Exception $e) {
|
|
return back()->withErrors(['error' => 'GWP gagal disimpan. Silakan coba lagi. Error: ' . $e->getMessage()]);
|
|
}
|
|
}
|
|
}
|