Started work on SiteDetails and Setup
This commit is contained in:
60
app/Http/Controllers/AdminHomeController.php
Normal file
60
app/Http/Controllers/AdminHomeController.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Models\SiteDetails;
|
||||
|
||||
class AdminHomeController extends Controller
|
||||
{
|
||||
public function setup()
|
||||
{
|
||||
return view('a.setup');
|
||||
}
|
||||
|
||||
public function setup_update(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'site_name' => 'required|string|max:255',
|
||||
'site_email' => 'required|string|email|max:255',
|
||||
'site_address1' => 'required|string|max:255',
|
||||
'site_address2' => 'nullable|string|max:255',
|
||||
'site_city' => 'required|string|max:64',
|
||||
'site_state' => 'required|string|max:32',
|
||||
'site_postcode' => 'required|string|max:8',
|
||||
'site_phone' => 'nullable|regex:/[0-9 ]+/|min:6|max:12',
|
||||
'site_fax' => 'nullable|regex:/[0-9 ]+/|min:6|max:12',
|
||||
]);
|
||||
|
||||
// If we are more input that sample data, reject the update.
|
||||
if (config('SITE_SETUP')->allowed_keys(array_keys($request->except('_token'))))
|
||||
return redirect()->back()
|
||||
->withInput()
|
||||
->withErrors('Invalid configuration - values not expected.');
|
||||
|
||||
foreach ($request->except('_token') as $key => $value)
|
||||
{
|
||||
if (! $value) {
|
||||
SiteDetails::where('site_id',config('SITE_SETUP')->id)->where('key',$key)->delete();
|
||||
|
||||
} else {
|
||||
try {
|
||||
|
||||
// Update or create our config record.
|
||||
SiteDetails::updateOrCreate([
|
||||
'site_id'=>config('SITE_SETUP')->id,
|
||||
'key'=>$key,
|
||||
],[
|
||||
'value'=>$value,
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
dd($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return redirect()->back()
|
||||
->with('success','Setup Updated!');;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user