From ea54f540deb43506836b57cbfe02616efbee84f6 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 7 Mar 2023 13:42:51 -0800 Subject: [PATCH] Dynamically determine target route for expected checkin emails Signed-off-by: snipe --- app/Models/Asset.php | 22 +++++++++++++++++++ .../report-expected-checkins.blade.php | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/app/Models/Asset.php b/app/Models/Asset.php index 9be0cd62b..e992298d8 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -547,6 +547,28 @@ class Asset extends Depreciable return strtolower(class_basename($this->assigned_type)); } + + + /** + * This is annoying, but because we don't say "assets" in our route names, we have to make an exception here + * @todo - normalize the route names - API endpoint URLS can stay the same + * + * @author [A. Gianotto] [] + * @since [v6.1.0] + * @return string + */ + public function targetShowRoute() + { + $route = str_plural($this->assignedType()); + if ($route=='assets') { + return 'hardware'; + } + + return $route; + + } + + /** * Get the asset's location based on default RTD location * diff --git a/resources/views/notifications/markdown/report-expected-checkins.blade.php b/resources/views/notifications/markdown/report-expected-checkins.blade.php index 9c8a13e80..3715188d4 100644 --- a/resources/views/notifications/markdown/report-expected-checkins.blade.php +++ b/resources/views/notifications/markdown/report-expected-checkins.blade.php @@ -10,7 +10,7 @@ @php $checkin = Helper::getFormattedDateObject($asset->expected_checkin, 'date'); @endphp -| [{{ $asset->present()->name }}]({{ route('hardware.show', ['hardware' => $asset->id]) }}) | [{{ $asset->assigned->present()->fullName }}]({{ route('users.show', ['user'=>$asset->assigned->id]) }}) | {{ $checkin['formatted'] }} +| [{{ $asset->present()->name }}]({{ route('hardware.show', ['hardware' => $asset->id]) }}) | [{{ $asset->assigned->present()->fullName }}]({{ route($asset->targetShowRoute().'.show', [$asset->assigned->id]) }}) | {{ $checkin['formatted'] }} @endforeach @endcomponent