jonnybarnes.uk/app/Models/Bookmark.php
Jonny Barnes 5481956d78
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 <noreply@anthropic.com>
2026-11-01 15:28:30 +00:00

34 lines
785 B
PHP

<?php
declare(strict_types=1);
namespace App\Models;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
#[Fillable(['url', 'name', 'content'])]
class Bookmark extends Model
{
use HasFactory;
/** @var array<string, string> */
protected $casts = [
'syndicates' => 'array',
];
public function tags(): BelongsToMany
{
return $this->belongsToMany('App\Models\Tag');
}
protected function uri(): Attribute
{
return Attribute::get(
get: fn () => config('app.url').'/bookmarks/'.$this->id,
);
}
}