Refactor models to use new attribute cast
This commit is contained in:
parent
a8de52077f
commit
cfca6a1de5
9 changed files with 218 additions and 292 deletions
|
@ -4,43 +4,11 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
/**
|
||||
* App\Models\Bookmark.
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $url
|
||||
* @property string|null $name
|
||||
* @property string|null $content
|
||||
* @property string|null $screenshot
|
||||
* @property string|null $archive
|
||||
* @property array|null $syndicates
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property-read string $longurl
|
||||
* @property-read Collection|Tag[] $tags
|
||||
* @property-read int|null $tags_count
|
||||
*
|
||||
* @method static Builder|Bookmark newModelQuery()
|
||||
* @method static Builder|Bookmark newQuery()
|
||||
* @method static Builder|Bookmark query()
|
||||
* @method static Builder|Bookmark whereArchive($value)
|
||||
* @method static Builder|Bookmark whereContent($value)
|
||||
* @method static Builder|Bookmark whereCreatedAt($value)
|
||||
* @method static Builder|Bookmark whereId($value)
|
||||
* @method static Builder|Bookmark whereName($value)
|
||||
* @method static Builder|Bookmark whereScreenshot($value)
|
||||
* @method static Builder|Bookmark whereSyndicates($value)
|
||||
* @method static Builder|Bookmark whereUpdatedAt($value)
|
||||
* @method static Builder|Bookmark whereUrl($value)
|
||||
* @mixin Eloquent
|
||||
*/
|
||||
class Bookmark extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
@ -71,13 +39,10 @@ class Bookmark extends Model
|
|||
return $this->belongsToMany('App\Models\Tag');
|
||||
}
|
||||
|
||||
/**
|
||||
* The full url of a bookmark.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLongurlAttribute(): string
|
||||
protected function longurl(): Attribute
|
||||
{
|
||||
return config('app.url') . '/bookmarks/' . $this->id;
|
||||
return Attribute::get(
|
||||
get: fn () => config('app.url') . '/bookmarks/' . $this->id,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue