From 5481956d7875482394d65aeefd9fb1ab720bce5b Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Sun, 1 Nov 2026 15:28:30 +0000 Subject: [PATCH] Use `uri` for the like and bookmark permalinks `uri` is the attribute every other postable model uses for its absolute permalink on this site. Add it to Like, which had none, and rename Bookmark's `local_uri` to match. `url` stays as the thing being liked or bookmarked. Refs #148 Co-Authored-By: Claude Opus 5.5 --- app/Models/Bookmark.php | 2 +- app/Models/Like.php | 7 +++++++ tests/Feature/BookmarksTest.php | 4 ++-- tests/Unit/LikesTest.php | 8 ++++++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/Models/Bookmark.php b/app/Models/Bookmark.php index 1c5ae6e4..5b37d84c 100644 --- a/app/Models/Bookmark.php +++ b/app/Models/Bookmark.php @@ -25,7 +25,7 @@ class Bookmark extends Model return $this->belongsToMany('App\Models\Tag'); } - protected function localUri(): Attribute + protected function uri(): Attribute { return Attribute::get( get: fn () => config('app.url').'/bookmarks/'.$this->id, diff --git a/app/Models/Like.php b/app/Models/Like.php index 44f25b91..8f2521ef 100644 --- a/app/Models/Like.php +++ b/app/Models/Like.php @@ -18,6 +18,13 @@ class Like extends Model use FilterHtml; use HasFactory; + protected function uri(): Attribute + { + return Attribute::get( + get: fn () => config('app.url').'/likes/'.$this->id, + ); + } + protected function url(): Attribute { return Attribute::set( diff --git a/tests/Feature/BookmarksTest.php b/tests/Feature/BookmarksTest.php index 83f36d32..fff9a267 100644 --- a/tests/Feature/BookmarksTest.php +++ b/tests/Feature/BookmarksTest.php @@ -92,10 +92,10 @@ class BookmarksTest extends TestCase } #[Test] - public function bookmark_local_uri_attribute_returns_correct_url(): void + public function bookmark_uri_attribute_returns_correct_url(): void { $bookmark = Bookmark::factory()->create(); - $this->assertEquals(config('app.url').'/bookmarks/'.$bookmark->id, $bookmark->local_uri); + $this->assertEquals(config('app.url').'/bookmarks/'.$bookmark->id, $bookmark->uri); } #[Test] diff --git a/tests/Unit/LikesTest.php b/tests/Unit/LikesTest.php index 74412833..ef4c21f2 100644 --- a/tests/Unit/LikesTest.php +++ b/tests/Unit/LikesTest.php @@ -13,6 +13,14 @@ class LikesTest extends TestCase { use RefreshDatabase; + #[Test] + public function like_uri_attribute_returns_our_permalink(): void + { + $like = Like::factory()->create(); + + $this->assertEquals(config('app.url').'/likes/'.$like->id, $like->uri); + } + #[Test] public function we_can_set_the_author_url(): void {