diff --git a/src/AdminLink.php b/src/AdminLink.php
index 562c740..42b462d 100644
--- a/src/AdminLink.php
+++ b/src/AdminLink.php
@@ -21,7 +21,7 @@ public function __construct(string $url, string $name, string $description = nul
$this->description = $description;
}
- public function getUrl(): string
+ public function getUrl(): ?string
{
return $this->url;
}
@@ -38,11 +38,16 @@ public function getDescription(): ?string
public function toHtml(): string
{
- $attributes[] = 'href="' . htmlspecialchars($this->getUrl()) . '"';
+ $attributes = [];
+
+ if ($this->getUrl()) {
+ $attributes[] = 'href="' . htmlspecialchars($this->getUrl()) . '"';
+ }
+
if ($this->getDescription()) {
$attributes[] = 'title="' . htmlspecialchars($this->getDescription()) . '"';
}
- return ''.$this->getName().'';
+ return '' . $this->getName() . '';
}
}
diff --git a/src/RouteAdminLink.php b/src/RouteAdminLink.php
index 0b4d9bc..06be640 100644
--- a/src/RouteAdminLink.php
+++ b/src/RouteAdminLink.php
@@ -2,6 +2,9 @@
namespace Kontenta\KontourSupport;
+use Illuminate\Support\Facades\Route;
+use Illuminate\Support\Facades\URL;
+
class RouteAdminLink extends AdminLink
{
protected $routeName;
@@ -13,8 +16,8 @@ public function __construct(string $routeName, string $name, string $description
$this->description = $description;
}
- public function getUrl(): string
+ public function getUrl(): ?string
{
- return route($this->routeName);
+ return Route::has($this->routeName) ? URL::route($this->routeName) : null;
}
}
diff --git a/tests/Feature/RouteAdminLinkTest.php b/tests/Feature/RouteAdminLinkTest.php
new file mode 100644
index 0000000..0030deb
--- /dev/null
+++ b/tests/Feature/RouteAdminLinkTest.php
@@ -0,0 +1,17 @@
+assertNull($link->getUrl());
+ $this->assertEquals('Hej', $link->toHtml());
+ }
+}