107 lines
2.9 KiB
PHP
107 lines
2.9 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace Modules\Setting\Http\Controllers;
|
||
|
|
||
|
use App\Http\Controllers\Controller;
|
||
|
use Illuminate\Http\RedirectResponse;
|
||
|
use Illuminate\Http\Request;
|
||
|
use Modules\Setting\Models\Setting;
|
||
|
use Modules\Setting\Repositories\SettingRepository;
|
||
|
|
||
|
class SettingController extends Controller
|
||
|
{
|
||
|
private $settingRepository;
|
||
|
/**
|
||
|
* Display a listing of the resource.
|
||
|
*/
|
||
|
public function __construct(
|
||
|
SettingRepository $settingRepository) {
|
||
|
$this->settingRepository = $settingRepository;
|
||
|
}
|
||
|
|
||
|
public function index()
|
||
|
{
|
||
|
$data['title'] = 'Categories List';
|
||
|
$data['categories'] = $this->settingRepository->findAll();
|
||
|
return view('setting::setting.edit', $data);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Show the form for creating a new resource.
|
||
|
*/
|
||
|
public function create()
|
||
|
{
|
||
|
$data['title'] = 'Create Setting';
|
||
|
$data['status'] = Setting::STATUS;
|
||
|
|
||
|
return view('setting::setting.edit', $data);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Store a newly created resource in storage.
|
||
|
*/
|
||
|
public function store(Request $request): RedirectResponse
|
||
|
{
|
||
|
$inputData = $request->all();
|
||
|
$this->settingRepository->create($inputData);
|
||
|
toastr()->success('Setting Created Succesfully');
|
||
|
$data['setting'] = $this->settingRepository->getSettingById($request->id);
|
||
|
|
||
|
return redirect()->route('setting.edit');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Show the specified resource.
|
||
|
*/
|
||
|
public function show($id)
|
||
|
{
|
||
|
$data['title'] = 'Show Setting';
|
||
|
$data['status'] = Setting::STATUS;
|
||
|
$data['setting'] = $this->settingRepository->getSettingById($id);
|
||
|
|
||
|
return view('setting::setting.edit', $data);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Show the form for editing the specified resource.
|
||
|
*/
|
||
|
public function edit($id)
|
||
|
{
|
||
|
$data['title'] = 'Edit Setting';
|
||
|
$data['status'] = Setting::STATUS;
|
||
|
|
||
|
$data['setting'] = $this->settingRepository->getSettingById($id);
|
||
|
|
||
|
return view('setting::setting.edit', $data);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Update the specified resource in storage.
|
||
|
*/
|
||
|
public function update(Request $request, $id): RedirectResponse
|
||
|
{
|
||
|
$inputData = $request->except(['_method', '_token']);
|
||
|
$this->settingRepository->update($id, $inputData);
|
||
|
$data['setting'] = $this->settingRepository->getSettingById($id);
|
||
|
|
||
|
return redirect()->route('setting.edit',$data);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Remove the specified resource from storage.
|
||
|
*/
|
||
|
public function destroy($id)
|
||
|
{
|
||
|
try {
|
||
|
$SettingModel = $this->settingRepository->getSettingById($id);
|
||
|
$SettingModel->delete();
|
||
|
|
||
|
toastr()->success('Product Delete Succesfully');
|
||
|
} catch (\Throwable $th) {
|
||
|
toastr()->error($th->getMessage());
|
||
|
}
|
||
|
|
||
|
return response()->json(['status' => true, 'message' => 'Setting Delete Succesfully']);
|
||
|
}
|
||
|
}
|