Skip to content

Commit

Permalink
Added the link_type_exists() helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
fulopattila122 committed May 24, 2023
1 parent 418bcfb commit 8efeb2c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## 3.x Series

## Unreleased
##### 2023-XX-YY

- Added the `link_type_exists()` helper function (to be used in blade templates)

## 3.7.0
##### 2023-04-04

Expand Down
9 changes: 9 additions & 0 deletions Support/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types=1);

use Vanilo\Links\Models\LinkTypeProxy;
use Vanilo\Links\Query\Get;

if (!function_exists('links')) {
Expand All @@ -21,3 +22,11 @@ function link_groups(string $type, string $property = null): Get
return null !== $property ? $result->basedOn($property) : $result;
}
}

if (!function_exists('link_type_exists')) {
function link_type_exists(string $type): bool
{
return LinkTypeProxy::whereSlug($type)->exists();
}
}

11 changes: 11 additions & 0 deletions Tests/Unit/LinkTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,15 @@ public function the_choices_method_can_return_slugs_as_keys()
'2019' => '2019',
], LinkType::choices(false, true));
}

/** @test */
public function the_link_type_exists_helper_function_can_tell_whether_a_certain_type_exists()
{
LinkType::create(['name' => 'Popular Companion']);
LinkType::create(['name' => 'Accessories']);

$this->assertTrue(link_type_exists('popular-companion'));
$this->assertTrue(link_type_exists('accessories'));
$this->assertFalse(link_type_exists('heavy-metal'));
}
}

0 comments on commit 8efeb2c

Please sign in to comment.