1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 05:32:39 +01:00
invoiceninja/app/Http/Requests/Product/UpdateProductRequest.php

66 lines
1.6 KiB
PHP
Raw Normal View History

2019-04-03 05:22:13 +02:00
<?php
2019-05-11 05:32:07 +02:00
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
2019-05-11 05:32:07 +02:00
*
* @license https://opensource.org/licenses/AAL
*/
2019-04-03 05:22:13 +02:00
namespace App\Http\Requests\Product;
use App\Http\Requests\Request;
use App\Models\Product;
use App\Utils\Traits\ChecksEntityStatus;
2019-04-03 05:22:13 +02:00
use Illuminate\Support\Facades\Log;
class UpdateProductRequest extends Request
{
use ChecksEntityStatus;
2019-04-03 05:22:13 +02:00
/**
* 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()
{
2020-06-22 13:41:04 +02:00
if ($this->input('documents') && is_array($this->input('documents'))) {
$documents = count($this->input('documents'));
foreach (range(0, $documents) as $index) {
$rules['documents.' . $index] = 'file|mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx|max:20000';
}
} elseif ($this->input('documents')) {
$rules['documents'] = 'file|mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx|max:20000';
}
$rules['cost'] = 'numeric';
$rules['price'] = 'numeric';
$rules['quantity'] = 'numeric';
return $rules;
2019-04-03 05:22:13 +02:00
}
2019-10-04 13:57:33 +02:00
protected function prepareForValidation()
2019-10-04 13:57:33 +02:00
{
$input = $this->all();
if (!isset($input['quantity']) || $input['quantity'] < 1) {
2019-10-04 13:57:33 +02:00
$input['quantity'] = 1;
}
2019-10-04 13:57:33 +02:00
$this->replace($input);
}
2019-04-03 05:22:13 +02:00
}