mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
Update a Product
This commit is contained in:
parent
39617644ad
commit
cb93b9ebe4
@ -8,6 +8,7 @@ use App\Http\Requests\Product\CreateProductRequest;
|
||||
use App\Http\Requests\Product\EditProductRequest;
|
||||
use App\Http\Requests\Product\ShowProductRequest;
|
||||
use App\Http\Requests\Product\StoreProductRequest;
|
||||
use App\Http\Requests\Product\UpdateProductRequest;
|
||||
use App\Models\Product;
|
||||
use App\Repositories\ProductRepository;
|
||||
use App\Transformers\ProductTransformer;
|
||||
@ -102,9 +103,11 @@ class ProductController extends BaseController
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
public function update(UpdateProductRequest $request, Product $product)
|
||||
{
|
||||
//
|
||||
$product = $this->product_repo->save($request, $product);
|
||||
|
||||
return $this->itemResponse($product);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -39,7 +39,7 @@ class QueryLogging
|
||||
$timeEnd = microtime(true);
|
||||
$time = $timeEnd - $timeStart;
|
||||
Log::info($request->method() . ' - ' . $request->url() . ": $count queries - " . $time);
|
||||
//Log::info($queries);
|
||||
Log::info($queries);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ class EditProductRequest extends Request
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'product_key' => 'required',
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Product;
|
||||
|
||||
//use Illuminate\Foundation\Http\FormRequest;
|
||||
use App\Http\Requests\Request;
|
||||
|
||||
class ShowProductRequest extends Request
|
||||
|
34
app/Http/Requests/Product/UpdateProductRequest.php
Normal file
34
app/Http/Requests/Product/UpdateProductRequest.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Product;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\Product;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class UpdateProductRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
|
||||
public function authorize() : bool
|
||||
{
|
||||
|
||||
return auth()->user()->can('create', Product::class);
|
||||
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
//when updating you need to ignore the column ID
|
||||
|
||||
return [
|
||||
'product_key' => 'required|unique:products,product_key,'.$this->product->id.',id,company_id,'.auth()->user()->companyId(),
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user