diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index ef628aa..f145d30 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -2,10 +2,11 @@ namespace App\Http\Controllers; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; -use Illuminate\Support\Arr; use Illuminate\Support\Facades\Auth; +use App\Http\Requests\SiteEdit; use App\Models\{Account, Charge, Invoice, @@ -187,63 +188,43 @@ class AdminController extends Controller * Site setup * * @note This method is protected by the routes - * @param Request $request - * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\Http\RedirectResponse + * @param SiteEdit $request + * @return RedirectResponse */ - public function setup(Request $request) + public function setup(SiteEdit $request) { - if ($request->post()) { - $validated = $request->validate([ - 'site_name' => 'required|string|min:2|max:255', - 'site_email' => 'required|string|email|max:255', - 'site_address1' => 'required|string|min:2|max:255', - 'site_address2' => 'nullable|string|min:2|max:255', - 'site_city' => 'required|string|min:2|max:64', - 'site_state' => 'required|string|min:2|max:32', - 'site_postcode' => 'required|string|min:2|max:8', - 'site_description' => 'nullable|string|min:5', - 'site_phone' => 'nullable|regex:/[0-9 ]+/|min:6|max:12', - 'site_fax' => 'nullable|regex:/[0-9 ]+/|min:6|max:12', - 'site_tax' => 'required|regex:/[0-9 ]+/|size:14', - 'social' => 'nullable|array', - 'top_menu' => 'nullable|array', - 'site_logo' => 'nullable|image', - 'email_logo' => 'nullable|image', - ]); + $site = config('site'); + $images = ['site_logo','email_logo']; + $validated = collect($request->validated()); - $site = config('site'); + // Handle the images + foreach($images as $key) + if ($x=$request->validated($key)) + $validated->put($key,$x->storeAs('site/'.$site->site_id,$x->getClientOriginalName(),'public')); - // @todo - not currently rendered in the home page - $validated['social'] = []; - $validated['top_menu'] = []; + foreach ($site->details as $oo) + if ($validated->has($oo->key)) { + // Dont set the following keys to null if they are null + if (in_array($oo->key,$images) && is_null($validated->get($oo->key))) + continue; - // Handle the images - foreach(['site_logo','email_logo'] as $key) - if (array_key_exists($key,$validated)) - $validated[$key] = ($x=$validated[$key])->storeAs('site/'.$site->site_id,$x->getClientOriginalName(),'public'); + $oo->value = $validated->get($oo->key) ?: ''; + $oo->save(); - foreach ($site->details as $oo) - if (array_key_exists($oo->key,$validated)) { - $oo->value = Arr::get($validated,$oo->key); - $oo->save(); - - unset($validated[$oo->key]); - } - - // Left over values to be created. - foreach ($validated as $k=>$v) { - $oo = new SiteDetail; - $oo->key = $k; - $oo->value = $v ?: ''; - - $site->details()->save($oo); + $validated->forget($oo->key); } - return redirect() - ->back() - ->with('success','Settings saved'); + // Left over values to be created. + foreach ($validated as $k=>$v) { + $oo = new SiteDetail; + $oo->key = $k; + $oo->value = $v ?: ''; + + $site->details()->save($oo); } - return view('theme.backend.adminlte.a.setup'); + return redirect() + ->back() + ->with('success','Settings saved'); } } \ No newline at end of file diff --git a/app/Http/Requests/SiteEdit.php b/app/Http/Requests/SiteEdit.php new file mode 100644 index 0000000..ee41ab8 --- /dev/null +++ b/app/Http/Requests/SiteEdit.php @@ -0,0 +1,43 @@ +|string> + */ + public function rules(): array + { + return [ + 'site_name' => 'required|string|min:2|max:255', + 'site_email' => 'required|string|email|max:255', + 'site_address1' => 'required|string|min:2|max:255', + 'site_address2' => 'nullable|string|min:2|max:255', + 'site_city' => 'required|string|min:2|max:64', + 'site_state' => 'required|string|min:2|max:32', + 'site_postcode' => 'required|string|min:2|max:8', + 'site_description' => 'nullable|string|min:5', + 'site_phone' => 'nullable|regex:/[0-9 ]+/|min:6|max:12', + 'site_fax' => 'nullable|regex:/[0-9 ]+/|min:6|max:12', + 'site_tax' => 'required|regex:/[0-9 ]+/|size:14', + 'social' => 'nullable|array', + 'top_menu' => 'nullable|array', + 'site_logo' => 'nullable|image', + 'email_logo' => 'nullable|image', + ]; + } +} \ No newline at end of file diff --git a/composer.lock b/composer.lock index f5254c2..61afdf7 100644 --- a/composer.lock +++ b/composer.lock @@ -2288,16 +2288,16 @@ }, { "name": "league/commonmark", - "version": "2.4.3", + "version": "2.5.0", "source": { "type": "git", "url": "https://github.com/thephpleague/commonmark.git", - "reference": "b7a7af3a23a818dcc5836e62e93e4b9ce4704481" + "reference": "0026475f5c9a104410ae824cb5a4d63fa3bdb1df" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/commonmark/zipball/b7a7af3a23a818dcc5836e62e93e4b9ce4704481", - "reference": "b7a7af3a23a818dcc5836e62e93e4b9ce4704481", + "url": "https://api.github.com/repos/thephpleague/commonmark/zipball/0026475f5c9a104410ae824cb5a4d63fa3bdb1df", + "reference": "0026475f5c9a104410ae824cb5a4d63fa3bdb1df", "shasum": "" }, "require": { @@ -2310,8 +2310,8 @@ }, "require-dev": { "cebe/markdown": "^1.0", - "commonmark/cmark": "0.30.3", - "commonmark/commonmark.js": "0.30.0", + "commonmark/cmark": "0.31.0", + "commonmark/commonmark.js": "0.31.0", "composer/package-versions-deprecated": "^1.8", "embed/embed": "^4.4", "erusev/parsedown": "^1.0", @@ -2333,7 +2333,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "2.5-dev" + "dev-main": "2.6-dev" } }, "autoload": { @@ -2390,7 +2390,7 @@ "type": "tidelift" } ], - "time": "2024-07-22T12:31:21+00:00" + "time": "2024-07-22T18:18:14+00:00" }, { "name": "league/config", @@ -3056,11 +3056,11 @@ }, { "name": "leenooks/laravel", - "version": "11.1.1", + "version": "11.1.2", "source": { "type": "git", "url": "https://gitea.dege.au/laravel/leenooks.git", - "reference": "b9a3cd564759218fd6b3bc1ebf58e798833f014e" + "reference": "f32c29fa8c4b189add48bde26b7b7115be49355f" }, "type": "library", "extra": { @@ -3093,7 +3093,7 @@ "laravel", "leenooks" ], - "time": "2024-07-22T14:11:06+00:00" + "time": "2024-07-23T08:47:36+00:00" }, { "name": "leenooks/passkey", diff --git a/resources/views/theme/backend/adminlte/a/setup.blade.php b/resources/views/theme/backend/adminlte/a/setup.blade.php index faf4049..1ce1edd 100644 --- a/resources/views/theme/backend/adminlte/a/setup.blade.php +++ b/resources/views/theme/backend/adminlte/a/setup.blade.php @@ -21,9 +21,7 @@