Upgrade to Laravel 10

This commit is contained in:
Jonny Barnes 2023-02-18 09:34:57 +00:00
parent c4d7dc31d5
commit 16b120bc73
Signed by: jonny
SSH key fingerprint: SHA256:CTuSlns5U7qlD9jqHvtnVmfYV3Zwl2Z7WnJ4/dqOaL8
142 changed files with 1676 additions and 2019 deletions

View file

@ -24,20 +24,24 @@ class Article extends Model
use Sluggable;
use SoftDeletes;
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
/**
* The database table used by the model.
*
* @var string
*/
/** @var string */
protected $table = 'articles';
/** @var array<int, string> */
protected $fillable = [
'url',
'title',
'main',
'published',
];
/** @var array<string, string> */
protected $casts = [
'created_at' => 'datetime',
'updated_at' => 'datetime',
'deleted_at' => 'datetime',
];
/**
* Return the sluggable configuration array for this model.
*/
@ -50,18 +54,6 @@ class Article extends Model
];
}
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'url',
'title',
'main',
'published',
];
protected function html(): Attribute
{
return Attribute::get(

View file

@ -13,28 +13,15 @@ class Bookmark extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
/** @var array<int, string> */
protected $fillable = ['url', 'name', 'content'];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
/** @var array<string, string> */
protected $casts = [
'syndicates' => 'array',
];
/**
* The tags that belong to the bookmark.
*
* @return BelongsToMany
*/
public function tags()
public function tags(): BelongsToMany
{
return $this->belongsToMany('App\Models\Tag');
}

View file

@ -12,18 +12,10 @@ class Contact extends Model
{
use HasFactory;
/**
* The database table used by the model.
*
* @var string
*/
/** @var string */
protected $table = 'contacts';
/**
* We shall guard against mass-migration.
*
* @var array
*/
/** @var array<int, string> */
protected $fillable = ['nick', 'name', 'homepage', 'twitter', 'facebook'];
protected function photo(): Attribute

View file

@ -16,6 +16,7 @@ class Like extends Model
use FilterHtml;
use HasFactory;
/** @var array<int, string> */
protected $fillable = ['url'];
protected function url(): Attribute

View file

@ -14,23 +14,12 @@ class Media extends Model
{
use HasFactory;
/**
* The table associated with the model.
*
* @var string
*/
/** @var string */
protected $table = 'media_endpoint';
/**
* The attributes that are mass assignable.
*
* @var array
*/
/** @var array<int, string> */
protected $fillable = ['token', 'path', 'type', 'image_widths'];
/**
* Get the note that owns this media.
*/
public function note(): BelongsTo
{
return $this->belongsTo(Note::class);

View file

@ -12,23 +12,12 @@ class MicropubClient extends Model
{
use HasFactory;
/**
* The table associated with the model.
*
* @var string
*/
/** @var string */
protected $table = 'clients';
/**
* The attributes that are mass assignable.
*
* @var array
*/
/** @var array<int, string> */
protected $fillable = ['client_url', 'client_name'];
/**
* Define the relationship with notes.
*/
public function notes(): HasMany
{
return $this->hasMany('App\Models\Note', 'client_id', 'client_url');

View file

@ -58,73 +58,46 @@ class Note extends Model
$this->contacts = null;
}
/**
* The database table used by the model.
*
* @var string
*/
/** @var string */
protected $table = 'notes';
/**
* Mass-assignment.
*
* @var array
*/
/** @var array<int, string> */
protected $fillable = [
'note',
'in_reply_to',
'client_id',
];
/**
* Hide the column used with Laravel Scout.
*
* @var array
*/
/** @var array<int, string> */
protected $hidden = ['searchable'];
/**
* Define the relationship with tags.
*/
public function tags(): BelongsToMany
{
return $this->belongsToMany(Tag::class);
}
/**
* Define the relationship with clients.
*/
public function client(): BelongsTo
{
return $this->belongsTo(MicropubClient::class, 'client_id', 'client_url');
}
/**
* Define the relationship with webmentions.
*/
public function webmentions(): MorphMany
{
return $this->morphMany(WebMention::class, 'commentable');
}
/**
* Define the relationship with places.
*/
public function place(): BelongsTo
{
return $this->belongsTo(Place::class);
}
/**
* Define the relationship with media.
*/
public function media(): HasMany
{
return $this->hasMany(Media::class);
}
/**
* Set the attributes to be indexed for searching with Scout.
* @return array<int, string>
*/
public function toSearchableArray(): array
{
@ -133,9 +106,6 @@ class Note extends Model
];
}
/**
* Normalize the note to Unicode FORM C.
*/
public function setNoteAttribute(?string $value): void
{
if ($value !== null) {
@ -195,58 +165,37 @@ class Note extends Model
return $note;
}
/**
* Generate the NewBase60 ID from primary ID.
*/
public function getNb60idAttribute(): string
{
// we cast to string because sometimes the nb60id is an “int”
return (string) resolve(Numbers::class)->numto60($this->id);
}
/**
* The Long URL for a note.
*/
public function getLongurlAttribute(): string
{
return config('app.url') . '/notes/' . $this->nb60id;
}
/**
* The Short URL for a note.
*/
public function getShorturlAttribute(): string
{
return config('app.shorturl') . '/notes/' . $this->nb60id;
}
/**
* Get the ISO8601 value for mf2.
*/
public function getIso8601Attribute(): string
{
return $this->updated_at->toISO8601String();
}
/**
* Get the ISO8601 value for mf2.
*/
public function getHumandiffAttribute(): string
{
return $this->updated_at->diffForHumans();
}
/**
* Get the publish date value for RSS feeds.
*/
public function getPubdateAttribute(): string
{
return $this->updated_at->toRSSString();
}
/**
* Get the latitude value.
*/
public function getLatitudeAttribute(): ?float
{
if ($this->place !== null) {
@ -262,9 +211,6 @@ class Note extends Model
return null;
}
/**
* Get the longitude value.
*/
public function getLongitudeAttribute(): ?float
{
if ($this->place !== null) {
@ -281,8 +227,9 @@ class Note extends Model
}
/**
* Get the address for a note. This is either a reverse geo-code from the
* location, or is derived from the associated place.
* Get the address for a note.
*
* This is either a reverse geo-code from the location, or is derived from the associated place.
*/
public function getAddressAttribute(): ?string
{
@ -337,9 +284,6 @@ class Note extends Model
* Show a specific form of the note for twitter.
*
* That is we swap the contacts names for their known Twitter handles.
*
*
* @throws TwitterContentException
*/
public function getTwitterContentAttribute(): string
{
@ -389,7 +333,7 @@ class Note extends Model
}
/**
* Swap contacts nicks for a full mf2 h-card.
* Swap contacts nicks for a full mf2 h-card.
*
* Take note that this method does two things, given @username (NOT [@username](URL)!)
* we try to create a fancy hcard from our contact info. If this is not possible
@ -473,9 +417,6 @@ class Note extends Model
);
}
/**
* Pass a note through the commonmark library.
*/
private function convertMarkdown(string $note): string
{
$config = [
@ -500,9 +441,6 @@ class Note extends Model
return $markdownConverter->convert($note)->getContent();
}
/**
* Do a reverse geocode lookup of a `lat,lng` value.
*/
public function reverseGeoCode(float $latitude, float $longitude): string
{
$latLng = $latitude . ',' . $longitude;

View file

@ -17,36 +17,20 @@ class Place extends Model
use HasFactory;
use Sluggable;
/**
* Get the route key for the model.
*
* @return string
*/
public function getRouteKeyName()
public function getRouteKeyName(): string
{
return 'slug';
}
/**
* The attributes that are mass assignable.
*
* @var array
*/
/** @var array<int, string> */
protected $fillable = ['name', 'slug'];
/**
* The attributes that should be cast.
*
* @var array
*/
/** @var array<string, string> */
protected $casts = [
'latitude' => 'float',
'longitude' => 'float',
];
/**
* Return the sluggable configuration array for this model.
*/
public function sluggable(): array
{
return [
@ -57,12 +41,7 @@ class Place extends Model
];
}
/**
* Define the relationship with Notes.
*
* @return HasMany
*/
public function notes()
public function notes(): HasMany
{
return $this->hasMany('App\Models\Note');
}

View file

@ -12,11 +12,7 @@ class SyndicationTarget extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
/** @var array<int, string> */
protected $fillable = [
'uid',
'name',
@ -28,11 +24,7 @@ class SyndicationTarget extends Model
'user_photo',
];
/**
* The attributes that are visible when serializing the model.
*
* @var array<string>
*/
/** @var array<int, string> */
protected $visible = [
'uid',
'name',
@ -40,21 +32,12 @@ class SyndicationTarget extends Model
'user',
];
/**
* The accessors to append to the model's array form.
*
* @var array
*/
/** @var array<int, string> */
protected $appends = [
'service',
'user',
];
/**
* Get the service data as a single attribute.
*
* @return Attribute
*/
protected function service(): Attribute
{
return Attribute::get(
@ -66,11 +49,6 @@ class SyndicationTarget extends Model
);
}
/**
* Get the user data as a single attribute.
*
* @vreturn Attribute
*/
protected function user(): Attribute
{
return Attribute::get(

View file

@ -14,29 +14,15 @@ class Tag extends Model
{
use HasFactory;
/**
* We shall set a blacklist of non-modifiable model attributes.
*
* @var array
*/
/** @var array<int, string> */
protected $guarded = ['id'];
/**
* Define the relationship with notes.
*
* @return BelongsToMany
*/
public function notes()
public function notes(): BelongsToMany
{
return $this->belongsToMany(Note::class);
}
/**
* The bookmarks that belong to the tag.
*
* @return BelongsToMany
*/
public function bookmarks()
public function bookmarks(): BelongsToMany
{
return $this->belongsToMany('App\Models\Bookmark');
}
@ -49,8 +35,9 @@ class Tag extends Model
}
/**
* This method actually normalizes a tag. That means lowercase-ing and
* removing fancy diatric characters.
* Normalizes a tag.
*
* That means convert to lowercase and removing fancy diatric characters.
*/
public static function normalize(string $tag): string
{

View file

@ -13,21 +13,15 @@ class User extends Authenticatable
use HasFactory;
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
/** @var array<int, string> */
protected $fillable = [
'name', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
/** @var array<int, string> */
protected $hidden = [
'password', 'remember_token',
'current_password',
'password',
'remember_token',
];
}

View file

@ -20,26 +20,13 @@ class WebMention extends Model
use FilterHtml;
use HasFactory;
/**
* The database table used by the model.
*
* @var string
*/
/** @var string */
protected $table = 'webmentions';
/**
* We shall set a blacklist of non-modifiable model attributes.
*
* @var array
*/
/** @var array<int, string> */
protected $guarded = ['id'];
/**
* Define the relationship.
*
* @return MorphTo
*/
public function commentable()
public function commentable(): MorphTo
{
return $this->morphTo();
}