this is a start, something up with asset_tag unique rule

This commit is contained in:
spencerrlongg 2023-10-31 21:06:44 -05:00
parent d4b9f6a2a4
commit b67b00dd82
2 changed files with 52 additions and 1 deletions

View file

@ -3,6 +3,7 @@
namespace App\Http\Controllers\Api;
use App\Events\CheckoutableCheckedIn;
use App\Http\Requests\StoreAssetRequest;
use Illuminate\Support\Facades\Gate;
use App\Helpers\Helper;
use App\Http\Controllers\Controller;
@ -33,6 +34,7 @@ use TCPDF;
use Validator;
use Route;
/**
* This class controls all actions related to assets for
* the Snipe-IT Asset Management application.
@ -532,7 +534,7 @@ class AssetsController extends Controller
* @since [v4.0]
* @return \Illuminate\Http\JsonResponse
*/
public function store(ImageUploadRequest $request)
public function store(StoreAssetRequest $request)
{
$this->authorize('create', Asset::class);

View file

@ -0,0 +1,49 @@
<?php
namespace App\Http\Requests;
use App\Models\Asset;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Gate;
class StoreAssetRequest extends ImageUploadRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize(): bool
{
//TODO: make sure this works
//return Gate::allows('create', new Asset);
}
public function prepareForValidation(): void
{
//
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
$rules = array_merge(
(new Asset)->getRules(),
parent::rules(),
);
if(!$this->expectsJson()) {
//accepts an array for the gui form
$rules['asset_tags.*'] = $rules['asset_tag'];
unset($rules['asset_tag']);
$rules['serials.*'] = $rules['serial'];
unset($rules['serial']);
}
return $rules;
}
}