diff --git a/app/Http/Controllers/ProductController.php b/app/Http/Controllers/ProductController.php index 7e3c825..09fec5e 100644 --- a/app/Http/Controllers/ProductController.php +++ b/app/Http/Controllers/ProductController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Collection; +use App\Http\Requests\ProductAddEdit; use App\Models\{Product,ProductTranslate}; class ProductController extends Controller @@ -65,37 +66,6 @@ class ProductController extends Controller */ public function details(Request $request,Product $o) { - if ($request->post()) { - $validation = $request->validate([ - 'description.name' => 'required|string|min:2|max:255', - 'active' => 'sometimes|accepted', - 'model' => 'sometimes|string', // @todo Check that it is a valid model type - 'model_id' => 'sometimes|int', // @todo Check that it is a valid model type - ]); - - foreach (collect($validation)->except('description') as $key => $item) - $o->{$key} = $item; - - $o->active = (bool)$request->active; - - try { - $o->save(); - } catch (\Exception $e) { - return redirect()->back()->withErrors($e->getMessage())->withInput(); - } - - $o->load(['description']); - $oo = $o->description ?: new ProductTranslate; - - foreach (collect($validation)->get('description',[]) as $key => $item) - $oo->{$key} = $item; - - $o->description()->save($oo); - - return redirect()->back() - ->with('success','Product saved'); - } - if (! $o->exists && $request->name) $o = Product::where('name',$request->name)->firstOrNew(); @@ -104,6 +74,31 @@ class ProductController extends Controller ->with('o',$o); } + public function details_addedit(ProductAddEdit $request,Product $o) + { + foreach ($request->except(['_token','submit','description']) as $key => $item) + $o->{$key} = $item; + + $o->active = (bool)$request->active; + + try { + $o->save(); + } catch (\Exception $e) { + return redirect()->back()->withErrors($e->getMessage())->withInput(); + } + + $o->load(['description']); + $oo = $o->description ?: new ProductTranslate; + + foreach ($request->get('description',[]) as $key => $item) + $oo->{$key} = $item; + + $o->description()->save($oo); + + return redirect()->back() + ->with('success','Product saved'); + } + /** * Manage products for a site * diff --git a/app/Http/Requests/ProductAddEdit.php b/app/Http/Requests/ProductAddEdit.php new file mode 100644 index 0000000..ea49d93 --- /dev/null +++ b/app/Http/Requests/ProductAddEdit.php @@ -0,0 +1,38 @@ +isWholesaler(); + } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules() + { + return [ + 'description.name' => 'required|string|min:2|max:100', + 'active' => 'sometimes|accepted', + 'model' => 'sometimes|string', // @todo Check that it is a valid model type + 'model_id' => 'sometimes|int', // @todo Check that it is a valid model type + 'accounting' => 'sometimes|string', + ]; + } +} \ No newline at end of file diff --git a/composer.lock b/composer.lock index 84199bd..16a28e0 100644 --- a/composer.lock +++ b/composer.lock @@ -2546,16 +2546,16 @@ }, { "name": "lcobucci/jwt", - "version": "4.1.5", + "version": "4.2.1", "source": { "type": "git", "url": "https://github.com/lcobucci/jwt.git", - "reference": "fe2d89f2eaa7087af4aa166c6f480ef04e000582" + "reference": "72ac6d807ee51a70ad376ee03a2387e8646e10f3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/lcobucci/jwt/zipball/fe2d89f2eaa7087af4aa166c6f480ef04e000582", - "reference": "fe2d89f2eaa7087af4aa166c6f480ef04e000582", + "url": "https://api.github.com/repos/lcobucci/jwt/zipball/72ac6d807ee51a70ad376ee03a2387e8646e10f3", + "reference": "72ac6d807ee51a70ad376ee03a2387e8646e10f3", "shasum": "" }, "require": { @@ -2571,12 +2571,12 @@ "infection/infection": "^0.21", "lcobucci/coding-standard": "^6.0", "mikey179/vfsstream": "^1.6.7", - "phpbench/phpbench": "^1.0", + "phpbench/phpbench": "^1.2", "phpstan/extension-installer": "^1.0", - "phpstan/phpstan": "^0.12", - "phpstan/phpstan-deprecation-rules": "^0.12", - "phpstan/phpstan-phpunit": "^0.12", - "phpstan/phpstan-strict-rules": "^0.12", + "phpstan/phpstan": "^1.4", + "phpstan/phpstan-deprecation-rules": "^1.0", + "phpstan/phpstan-phpunit": "^1.0", + "phpstan/phpstan-strict-rules": "^1.0", "phpunit/php-invoker": "^3.1", "phpunit/phpunit": "^9.5" }, @@ -2604,7 +2604,7 @@ ], "support": { "issues": "https://github.com/lcobucci/jwt/issues", - "source": "https://github.com/lcobucci/jwt/tree/4.1.5" + "source": "https://github.com/lcobucci/jwt/tree/4.2.1" }, "funding": [ { @@ -2616,7 +2616,7 @@ "type": "patreon" } ], - "time": "2021-09-28T19:34:56+00:00" + "time": "2022-08-19T23:14:07+00:00" }, { "name": "league/commonmark", @@ -3411,11 +3411,11 @@ }, { "name": "leenooks/laravel", - "version": "9.2.6", + "version": "9.2.7", "source": { "type": "git", "url": "https://dev.leenooks.net/leenooks/laravel", - "reference": "e3ebef90d94e8f04dfeafd1cff3607204bd5e989" + "reference": "05d3caddf49818098a691706df64f1decff08a84" }, "require": { "creativeorange/gravatar": "^1.0", @@ -3454,7 +3454,7 @@ "laravel", "leenooks" ], - "time": "2022-08-19T05:11:09+00:00" + "time": "2022-08-20T13:06:26+00:00" }, { "name": "leenooks/laravel-theme", @@ -9191,23 +9191,23 @@ }, { "name": "phpunit/php-code-coverage", - "version": "9.2.15", + "version": "9.2.16", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "2e9da11878c4202f97915c1cb4bb1ca318a63f5f" + "reference": "2593003befdcc10db5e213f9f28814f5aa8ac073" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/2e9da11878c4202f97915c1cb4bb1ca318a63f5f", - "reference": "2e9da11878c4202f97915c1cb4bb1ca318a63f5f", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/2593003befdcc10db5e213f9f28814f5aa8ac073", + "reference": "2593003befdcc10db5e213f9f28814f5aa8ac073", "shasum": "" }, "require": { "ext-dom": "*", "ext-libxml": "*", "ext-xmlwriter": "*", - "nikic/php-parser": "^4.13.0", + "nikic/php-parser": "^4.14", "php": ">=7.3", "phpunit/php-file-iterator": "^3.0.3", "phpunit/php-text-template": "^2.0.2", @@ -9256,7 +9256,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.15" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.16" }, "funding": [ { @@ -9264,7 +9264,7 @@ "type": "github" } ], - "time": "2022-03-07T09:28:20+00:00" + "time": "2022-08-20T05:26:47+00:00" }, { "name": "phpunit/php-file-iterator", @@ -9509,16 +9509,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.5.21", + "version": "9.5.22", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "0e32b76be457de00e83213528f6bb37e2a38fcb1" + "reference": "e329ac6e8744f461518272612a479fde958752fe" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/0e32b76be457de00e83213528f6bb37e2a38fcb1", - "reference": "0e32b76be457de00e83213528f6bb37e2a38fcb1", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/e329ac6e8744f461518272612a479fde958752fe", + "reference": "e329ac6e8744f461518272612a479fde958752fe", "shasum": "" }, "require": { @@ -9595,7 +9595,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.21" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.22" }, "funding": [ { @@ -9607,7 +9607,7 @@ "type": "github" } ], - "time": "2022-06-19T12:14:25+00:00" + "time": "2022-08-20T08:25:46+00:00" }, { "name": "sebastian/cli-parser", diff --git a/resources/views/theme/backend/adminlte/product/details.blade.php b/resources/views/theme/backend/adminlte/product/details.blade.php index bf8c89e..6206f73 100644 --- a/resources/views/theme/backend/adminlte/product/details.blade.php +++ b/resources/views/theme/backend/adminlte/product/details.blade.php @@ -14,12 +14,6 @@ @endsection @section('main-content') -
-
- @include('adminlte::widget.status') -
-
-
diff --git a/resources/views/theme/backend/adminlte/product/widget/detail.blade.php b/resources/views/theme/backend/adminlte/product/widget/detail.blade.php index 3c29ab5..3c63a93 100644 --- a/resources/views/theme/backend/adminlte/product/widget/detail.blade.php +++ b/resources/views/theme/backend/adminlte/product/widget/detail.blade.php @@ -1,11 +1,9 @@
-

Product Details

+

Product Details @include('adminlte::widget.success_button')


- @if(session()->has('success')) - {{ session()->get('success') }} - @endif +
@csrf @@ -16,7 +14,7 @@ @include('adminlte::widget.form_text',[ 'label'=>'Product Name', 'icon'=>'fas fa-atom', - 'id'=>'name', + 'id'=>'description.name', 'old'=>'description.name', 'name'=>'description[name]', 'value'=>$o->name ?? '', @@ -70,6 +68,20 @@
+
+ +
+ @include('adminlte::widget.form_text',[ + 'label'=>'Accounting', + 'icon'=>'fas fa-calculator', + 'id'=>'accounting', + 'old'=>'accounting', + 'name'=>'accounting', + 'value'=>$o->accounting ?? '', + ]) +
+
+
diff --git a/routes/web.php b/routes/web.php index 59aecc5..804dd0c 100644 --- a/routes/web.php +++ b/routes/web.php @@ -74,7 +74,9 @@ Route::group(['middleware'=>['theme:adminlte-be','auth','role:wholesaler'],'pref // Product Setup Route::match(['get'],'product',[ProductController::class,'home']); - Route::match(['get','post'],'product/details/{o?}',[ProductController::class,'details']) + Route::get('product/details/{o?}',[ProductController::class,'details']) + ->where('o','[0-9]+'); + Route::post('product/details/{o?}',[ProductController::class,'details_addedit']) ->where('o','[0-9]+'); // Supplier Setup