Skip to content

Adds a check for assigned target not being null when creating an asset #16675

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions app/Http/Controllers/Assets/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,31 @@ public function store(ImageUploadRequest $request) : RedirectResponse

// Validate the asset before saving
if ($asset->isValid() && $asset->save()) {
if (request('assigned_user')) {
$target = User::find(request('assigned_user'));
$target = null;
$location = null;

if ($userId = request('assigned_user')) {
$target = User::find($userId);

if (!$target) {
return redirect()->back()->withInput()->with('error', trans('admin/hardware/message.create.target_not_found.user'));
}
$location = $target->location_id;
} elseif (request('assigned_asset')) {
$target = Asset::find(request('assigned_asset'));

} elseif ($assetId = request('assigned_asset')) {
$target = Asset::find($assetId);

if (!$target) {
return redirect()->back()->withInput()->with('error', trans('admin/hardware/message.create.target_not_found.asset'));
}
$location = $target->location_id;
} elseif (request('assigned_location')) {
$target = Location::find(request('assigned_location'));

} elseif ($locationId = request('assigned_location')) {
$target = Location::find($locationId);

if (!$target) {
return redirect()->back()->withInput()->with('error', trans('admin/hardware/message.create.target_not_found.location'));
}
$location = $target->id;
}

Expand Down
5 changes: 5 additions & 0 deletions resources/lang/en-US/admin/hardware/message.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
'success_linked' => 'Asset with tag :tag was created successfully. <strong><a href=":link" style="color: white;">Click here to view</a></strong>.',
'multi_success_linked' => 'Asset with tag :links was created successfully.|:count assets were created succesfully. :links.',
'partial_failure' => 'An asset was unable to be created. Reason: :failures|:count assets were unable to be created. Reasons: :failures',
'target_not_found' => [
'user' => 'The assigned user could not be found.',
'asset' => 'The assigned asset could not be found.',
'location' => 'The assigned location could not be found.',
],
],

'update' => [
Expand Down
Loading