Skip to content

Commit ddead35

Browse files
authored
Merge pull request #15660 from Toreg87/fixes/api_asset_create_fmcs2
Refactor asset creation with API
2 parents 0d35335 + f3c4e55 commit ddead35

File tree

2 files changed

+1
-9
lines changed

2 files changed

+1
-9
lines changed

app/Http/Controllers/Api/AssetsController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,6 @@ public function store(StoreAssetRequest $request): JsonResponse
598598
$asset->model()->associate(AssetModel::find((int) $request->get('model_id')));
599599

600600
$asset->fill($request->validated());
601-
$asset->company_id = Company::getIdForCurrentUser($request->validated()['company_id']);
602601
$asset->created_by = auth()->id();
603602

604603
/**

app/Http/Requests/StoreAssetRequest.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,11 @@ public function authorize(): bool
2626

2727
public function prepareForValidation(): void
2828
{
29-
// Guard against users passing in an array for company_id instead of an integer.
30-
// If the company_id is not an integer then we simply use what was
31-
// provided to be caught by model level validation later.
32-
$idForCurrentUser = is_int($this->company_id)
33-
? Company::getIdForCurrentUser($this->company_id)
34-
: $this->company_id;
35-
3629
$this->parseLastAuditDate();
3730

3831
$this->merge([
3932
'asset_tag' => $this->asset_tag ?? Asset::autoincrement_asset(),
40-
'company_id' => $idForCurrentUser,
33+
'company_id' => Company::getIdForCurrentUser($this->company_id),
4134
'assigned_to' => $assigned_to ?? null,
4235
]);
4336
}

0 commit comments

Comments
 (0)