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 @@

Setup Configuration

- @if(session()->has('success')) - {{ session()->get('success') }} - @endif +
@@ -31,182 +29,69 @@ @csrf
-
+
-
-
- - - - @error('site_name') - {{ $message }} - @else - Organisation Name is required. - @enderror - - System Name used everywhere. -
+
+
-
-
- - - - @error('site_logo') - {{ $message }} - @enderror - -
+
+ +
-
-
- - - - @error('email_logo') - {{ $message }} - @enderror - -
+
+ +
+
+ +
+
+ +
+
+
-
-
-
-
- - - - - @error('site_address1') - {{ $message }} - @else - Atleast 1 address line required. - @enderror - -
-
-
- -
-
-
- - - - @error('site_city') - {{ $message }} - @else - City is required. - @enderror - -
-
-
- -
-
-
- - - - @error('site_state') - {{ $message }} - @else - State is required. - @enderror - -
- -
- - - - @error('site_postcode') - {{ $message }} - @else - Postcode is required. - @enderror - -
-
-
+
+ + + +
-
-
- - - - @error('site_phone') - {{ $message }} - @enderror - +
+
+
+ +
-
- - - - @error('site_fax') - {{ $message }} - @enderror - -
- -
- - - - @error('site_email') - {{ $message }} - @else - Email required. - @enderror - -
- -
- - ABN - - - @error('site_tax') - {{ $message }} - @enderror - +
+
+ +
-
- - - Brief description of site. - - @error('site_description') - {{ $message }} - @enderror - -
+
- Cancel + @can('wholesaler') - + Save @endcan
diff --git a/resources/views/theme/backend/adminlte/user/settings.blade.php b/resources/views/theme/backend/adminlte/user/settings.blade.php index 66cb156..9664c88 100644 --- a/resources/views/theme/backend/adminlte/user/settings.blade.php +++ b/resources/views/theme/backend/adminlte/user/settings.blade.php @@ -22,7 +22,7 @@
Update Settings
- @session('success'){{ $value }}@endsession +
@@ -45,7 +45,7 @@
- +
@@ -101,8 +101,8 @@
- - + + Save
diff --git a/routes/web.php b/routes/web.php index 7589878..402170f 100644 --- a/routes/web.php +++ b/routes/web.php @@ -63,7 +63,8 @@ Route::get('admin/switch/stop',[SwitchUserController::class,'switch_stop']) // Our Admin Routes - for wholesalers Route::group(['middleware'=>['auth','role:wholesaler'],'prefix'=>'a'],function() { // Site Setup - Route::match(['get','post'],'setup',[AdminController::class,'setup']); + Route::view('setup','theme.backend.adminlte.a.setup'); + Route::post('setup',[AdminController::class,'setup']); // Checkout Setup (Payments) Route::get('checkout',[CheckoutController::class,'home']);