2024-02-26 12:32:50 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
|
2024-07-30 19:22:46 -07:00
|
|
|
use App\Http\Requests\Traits\MayContainCustomFields;
|
2024-02-26 12:32:50 -08:00
|
|
|
use App\Models\Asset;
|
2024-08-29 04:35:14 -07:00
|
|
|
use App\Models\Setting;
|
2024-02-26 12:32:50 -08:00
|
|
|
use Illuminate\Support\Facades\Gate;
|
2024-03-13 13:57:10 -07:00
|
|
|
use Illuminate\Validation\Rule;
|
2024-02-26 12:32:50 -08:00
|
|
|
|
|
|
|
class UpdateAssetRequest extends ImageUploadRequest
|
|
|
|
{
|
2024-07-30 19:22:46 -07:00
|
|
|
use MayContainCustomFields;
|
2024-02-26 12:32:50 -08:00
|
|
|
/**
|
|
|
|
* Determine if the user is authorized to make this request.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function authorize()
|
|
|
|
{
|
2024-07-23 12:29:17 -07:00
|
|
|
return Gate::allows('update', $this->asset);
|
2024-02-26 12:32:50 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the validation rules that apply to the request.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function rules()
|
|
|
|
{
|
2024-04-23 14:29:07 -07:00
|
|
|
$rules = array_merge(
|
|
|
|
parent::rules(),
|
|
|
|
(new Asset)->getRules(),
|
2024-04-25 15:17:42 -07:00
|
|
|
// this is to overwrite rulesets that include required, and rewrite unique_undeleted
|
2024-04-23 14:29:07 -07:00
|
|
|
[
|
|
|
|
'model_id' => ['integer', 'exists:models,id,deleted_at,NULL', 'not_array'],
|
|
|
|
'status_id' => ['integer', 'exists:status_labels,id'],
|
|
|
|
'asset_tag' => [
|
|
|
|
'min:1', 'max:255', 'not_array',
|
|
|
|
Rule::unique('assets', 'asset_tag')->ignore($this->asset)->withoutTrashed()
|
|
|
|
],
|
|
|
|
],
|
2024-03-21 07:26:45 -07:00
|
|
|
);
|
2024-04-23 15:35:33 -07:00
|
|
|
|
2024-08-29 04:35:14 -07:00
|
|
|
// if the purchase cost is passed in as a string **and** the digit_separator is ',' (as is common in the EU)
|
|
|
|
// then we tweak the purchase_cost rule to make it a string
|
|
|
|
if (Setting::getSettings()->digit_separator === '1.234,56' && is_string($this->input('purchase_cost'))) {
|
|
|
|
$rules['purchase_cost'] = ['nullable', 'string'];
|
|
|
|
}
|
|
|
|
|
2024-07-01 17:37:49 -07:00
|
|
|
return $rules;
|
2024-02-26 12:32:50 -08:00
|
|
|
}
|
|
|
|
}
|