first change
This commit is contained in:
63
Modules/Admin/app/Http/Controllers/SettingController.php
Normal file
63
Modules/Admin/app/Http/Controllers/SettingController.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\Http\Controllers;
|
||||
use Cache;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Modules\Admin\Models\Setting;
|
||||
use Modules\Admin\Repositories\SettingInterface;
|
||||
|
||||
class SettingController extends Controller
|
||||
{
|
||||
private $setting;
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
|
||||
public function __construct(SettingInterface $setting)
|
||||
{
|
||||
$this->setting = $setting;
|
||||
}
|
||||
public function index()
|
||||
{
|
||||
$data['title'] = "Edit Setting";
|
||||
$data['editable'] = true;
|
||||
$data['setting'] = $this->setting->findAll();
|
||||
|
||||
return view('admin::settings.edit', $data);
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
try {
|
||||
$input = $request->except([
|
||||
'_method',
|
||||
'_token',
|
||||
]);
|
||||
if ($request->hasFile('logo_pic')) {
|
||||
$input['logo_pic'] = uploadImage($request->logo_pic);
|
||||
}
|
||||
|
||||
foreach ($input as $key => $item) {
|
||||
$finalInput = [
|
||||
'key' => $key,
|
||||
'value' => $item,
|
||||
];
|
||||
Setting::updateOrInsert(['key' => $key], $finalInput);
|
||||
|
||||
}
|
||||
Cache::has('setting') ? Cache::forget('setting') : '';
|
||||
return redirect()->route('setting.index')->with('success', 'Setting Updated');
|
||||
} catch (\Throwable $th) {
|
||||
return redirect()->back()->withError($th->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->setting->delete($id);
|
||||
return response()->json(['status' => true]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user