rbrecruiter/app/Http/Controllers/OptionsController.php

58 lines
1.5 KiB
PHP
Raw Normal View History

2020-08-30 22:06:01 +00:00
<?php
namespace App\Http\Controllers;
use App\Helpers\Options;
2020-08-31 16:55:36 +00:00
use App\Options as Option;
2020-08-30 22:06:01 +00:00
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class OptionsController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Http\Response|\Illuminate\View\View
*/
public function index()
{
2020-08-31 16:55:36 +00:00
// TODO: Obtain this from the facade
$options = Option::all();
2020-08-30 22:06:01 +00:00
2020-08-31 16:58:07 +00:00
return view('dashboard.administration.settings')
2020-08-31 16:55:36 +00:00
->with('options', $options);
2020-08-30 22:06:01 +00:00
}
public function saveSettings(Request $request)
{
2020-08-31 17:36:38 +00:00
if (Auth::user()->can('admin.settings.edit'))
2020-08-30 22:06:01 +00:00
{
foreach($request->all() as $optionName => $option)
{
try
{
if (Options::optionExists($option))
{
Options::changeOption($optionName, $option);
}
}
catch(\Exception $ex)
{
2020-08-31 18:47:27 +00:00
$request->session()->flash('error', 'An error occurred while trying to save settings: ' . $ex->getMessage());
exit;
2020-08-30 22:06:01 +00:00
}
}
$request->session()->flash('success', 'Settings saved successfully!');
}
else
{
$request->session()->flash('error', 'You do not have permission to update this resource.');
}
return redirect()->back();
}
}