2016-05-19 15:01:28 +01:00
|
|
|
<?php
|
|
|
|
|
|
2018-01-15 14:02:13 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2017-12-19 16:00:42 +00:00
|
|
|
namespace App\Models;
|
2016-05-19 15:01:28 +01:00
|
|
|
|
2026-04-07 09:01:19 +01:00
|
|
|
use Illuminate\Database\Eloquent\Attributes\Guarded;
|
2022-11-26 10:50:19 +00:00
|
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
2020-10-19 19:41:50 +01:00
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
2016-05-19 15:01:28 +01:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2020-02-22 11:06:43 +00:00
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
2021-04-29 20:02:20 +01:00
|
|
|
use Illuminate\Support\Str;
|
2016-05-19 15:01:28 +01:00
|
|
|
|
2026-04-07 09:01:19 +01:00
|
|
|
#[Guarded(['id'])]
|
2016-05-19 15:01:28 +01:00
|
|
|
class Tag extends Model
|
|
|
|
|
{
|
2020-10-19 19:41:50 +01:00
|
|
|
use HasFactory;
|
|
|
|
|
|
2023-02-18 09:34:57 +00:00
|
|
|
public function notes(): BelongsToMany
|
2016-05-19 15:01:28 +01:00
|
|
|
{
|
2021-08-31 12:28:00 +01:00
|
|
|
return $this->belongsToMany(Note::class);
|
2016-05-19 15:01:28 +01:00
|
|
|
}
|
|
|
|
|
|
2023-02-18 09:34:57 +00:00
|
|
|
public function bookmarks(): BelongsToMany
|
2017-10-10 15:58:07 +01:00
|
|
|
{
|
2017-12-19 16:00:42 +00:00
|
|
|
return $this->belongsToMany('App\Models\Bookmark');
|
2017-10-10 15:58:07 +01:00
|
|
|
}
|
|
|
|
|
|
2022-11-26 10:50:19 +00:00
|
|
|
protected function tag(): Attribute
|
2016-05-29 13:49:30 +01:00
|
|
|
{
|
2022-11-26 10:50:19 +00:00
|
|
|
return Attribute::set(
|
|
|
|
|
set: fn ($value) => self::normalize($value),
|
|
|
|
|
);
|
2016-05-29 13:49:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-02-18 09:34:57 +00:00
|
|
|
* Normalizes a tag.
|
|
|
|
|
*
|
|
|
|
|
* That means convert to lowercase and removing fancy diatric characters.
|
2016-05-29 13:49:30 +01:00
|
|
|
*/
|
2018-01-15 14:02:13 +00:00
|
|
|
public static function normalize(string $tag): string
|
2016-05-29 13:49:30 +01:00
|
|
|
{
|
2021-04-29 20:02:20 +01:00
|
|
|
return Str::slug($tag);
|
2016-05-29 13:49:30 +01:00
|
|
|
}
|
2016-05-19 15:01:28 +01:00
|
|
|
}
|