Editing product and enabled updating the accounting field

This commit is contained in:
Deon George 2022-08-20 23:35:41 +10:00
parent 8d920e1ba1
commit 8955df84cd
6 changed files with 111 additions and 70 deletions

View File

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

View File

@ -0,0 +1,38 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;
/**
* Editing Suppliers
*/
class ProductAddEdit extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return Auth::user()->isWholesaler();
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, mixed>
*/
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',
];
}
}

54
composer.lock generated
View File

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

View File

@ -14,12 +14,6 @@
@endsection
@section('main-content')
<div class="row">
<div class="col-12">
@include('adminlte::widget.status')
</div>
</div>
<div class="row">
<div class="col-12">
<div class="card">

View File

@ -1,11 +1,9 @@
<!-- $o = Product::class -->
<div class="row">
<div class="col-12">
<h3>Product Details</h3>
<h3>Product Details @include('adminlte::widget.success_button')</h3>
<hr>
@if(session()->has('success'))
<span class="ml-3 pt-0 pb-0 pr-1 pl-1 btn btn-outline-success"><small>{{ session()->get('success') }}</small></span>
@endif
<form class="g-0 needs-validation" method="POST" enctype="multipart/form-data" role="form">
@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 @@
</div>
</div>
<div class="row">
<!-- Accounting -->
<div class="col-12 col-sm-9 col-md-12 col-xl-6">
@include('adminlte::widget.form_text',[
'label'=>'Accounting',
'icon'=>'fas fa-calculator',
'id'=>'accounting',
'old'=>'accounting',
'name'=>'accounting',
'value'=>$o->accounting ?? '',
])
</div>
</div>
<div class="row">
<!-- Buttons -->
<div class="col-12">

View File

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