mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-app.git
synced 2026-07-02 09:00:23 +00:00
✨ Refactor components and models:
- 🔥 Removed deprecated `placeholder-pattern` component. - 🧹 Simplified and cleaned up Blade views by removing unused comments and sections. - 🗂️ Extracted `SetsCreatedBy` concern for DRY and reused it across models. - 🔧 Consolidated configuration for Horizon `authorized_nostr_keys`. - 🧪 Migrated media conversion to use new Spatie enums for clarity. - ♻️ Replaced repetitive link rendering with dynamic rendering in meetups and services views.
This commit is contained in:
@@ -2,10 +2,11 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Concerns\SetsCreatedBy;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Spatie\Image\Manipulations;
|
||||
use Spatie\Image\Enums\Fit;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
||||
@@ -14,6 +15,7 @@ class BitcoinEvent extends Model implements HasMedia
|
||||
{
|
||||
use HasFactory;
|
||||
use InteractsWithMedia;
|
||||
use SetsCreatedBy;
|
||||
|
||||
/**
|
||||
* The attributes that aren't mass assignable.
|
||||
@@ -34,23 +36,14 @@ class BitcoinEvent extends Model implements HasMedia
|
||||
'to' => 'datetime',
|
||||
];
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::creating(function ($model) {
|
||||
if (! $model->created_by) {
|
||||
$model->created_by = auth()->id();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function registerMediaConversions(?Media $media = null): void
|
||||
{
|
||||
$this
|
||||
->addMediaConversion('preview')
|
||||
->fit(Manipulations::FIT_CROP, 300, 300)
|
||||
->fit(Fit::Crop, 300, 300)
|
||||
->nonQueued();
|
||||
$this->addMediaConversion('thumb')
|
||||
->fit(Manipulations::FIT_CROP, 130, 130)
|
||||
->fit(Fit::Crop, 130, 130)
|
||||
->width(130)
|
||||
->height(130);
|
||||
}
|
||||
|
||||
+6
-13
@@ -3,6 +3,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Akuechler\Geoly;
|
||||
use App\Models\Concerns\SetsCreatedBy;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
@@ -13,9 +14,10 @@ use Spatie\Sluggable\SlugOptions;
|
||||
|
||||
class City extends Model
|
||||
{
|
||||
use Geoly;
|
||||
use HasFactory;
|
||||
use HasSlug;
|
||||
use Geoly;
|
||||
use SetsCreatedBy;
|
||||
|
||||
/**
|
||||
* The attributes that aren't mass assignable.
|
||||
@@ -36,24 +38,15 @@ class City extends Model
|
||||
'simplified_geojson' => 'json',
|
||||
];
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::creating(function ($model) {
|
||||
if (! $model->created_by) {
|
||||
$model->created_by = auth()->id();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the options for generating the slug.
|
||||
*/
|
||||
public function getSlugOptions(): SlugOptions
|
||||
{
|
||||
return SlugOptions::create()
|
||||
->generateSlugsFrom(['country.code', 'name'])
|
||||
->saveSlugsTo('slug')
|
||||
->usingLanguage(Cookie::get('lang', config('app.locale')));
|
||||
->generateSlugsFrom(['country.code', 'name'])
|
||||
->saveSlugsTo('slug')
|
||||
->usingLanguage(Cookie::get('lang', config('app.locale')));
|
||||
}
|
||||
|
||||
public function createdBy(): BelongsTo
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Concerns;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
trait SetsCreatedBy
|
||||
{
|
||||
public static function bootSetsCreatedBy(): void
|
||||
{
|
||||
static::creating(function (Model $model): void {
|
||||
if (auth()->check() && ! $model->created_by) {
|
||||
$model->created_by = auth()->id();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Concerns\SetsCreatedBy;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
@@ -18,6 +19,7 @@ class Course extends Model implements HasMedia
|
||||
use HasFactory;
|
||||
use HasTags;
|
||||
use InteractsWithMedia;
|
||||
use SetsCreatedBy;
|
||||
|
||||
/**
|
||||
* @var array<int, string>
|
||||
@@ -38,15 +40,6 @@ class Course extends Model implements HasMedia
|
||||
'lecturer_id' => 'integer',
|
||||
];
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::creating(function ($model) {
|
||||
if (! $model->created_by) {
|
||||
$model->created_by = auth()->id();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function registerMediaConversions(?Media $media = null): void
|
||||
{
|
||||
$this
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Concerns\SetsCreatedBy;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
@@ -10,6 +11,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
class CourseEvent extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use SetsCreatedBy;
|
||||
|
||||
/**
|
||||
* The attributes that aren't mass assignable.
|
||||
@@ -31,15 +33,6 @@ class CourseEvent extends Model
|
||||
'to' => 'datetime',
|
||||
];
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::creating(function ($model) {
|
||||
if (! $model->created_by) {
|
||||
$model->created_by = auth()->id();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function createdBy(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'created_by');
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Concerns\SetsCreatedBy;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
@@ -12,6 +13,7 @@ class Episode extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasTags;
|
||||
use SetsCreatedBy;
|
||||
|
||||
/**
|
||||
* The attributes that aren't mass assignable.
|
||||
@@ -31,15 +33,6 @@ class Episode extends Model
|
||||
'data' => 'array',
|
||||
];
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::creating(function ($model) {
|
||||
if (! $model->created_by) {
|
||||
$model->created_by = auth()->id();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function createdBy(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'created_by');
|
||||
|
||||
+2
-14
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Concerns\SetsCreatedBy;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
@@ -20,6 +21,7 @@ class Lecturer extends Model implements HasMedia
|
||||
use HasFactory;
|
||||
use HasSlug;
|
||||
use InteractsWithMedia;
|
||||
use SetsCreatedBy;
|
||||
|
||||
/**
|
||||
* @var array<int, string>
|
||||
@@ -51,15 +53,6 @@ class Lecturer extends Model implements HasMedia
|
||||
'active' => 'boolean',
|
||||
];
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::creating(function ($model) {
|
||||
if (! $model->created_by) {
|
||||
$model->created_by = auth()->id();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function registerMediaConversions(?Media $media = null): void
|
||||
{
|
||||
$this
|
||||
@@ -99,11 +92,6 @@ class Lecturer extends Model implements HasMedia
|
||||
return $this->belongsTo(User::class, 'created_by');
|
||||
}
|
||||
|
||||
public function team(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Team::class);
|
||||
}
|
||||
|
||||
public function courses(): HasMany
|
||||
{
|
||||
return $this->hasMany(Course::class);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Concerns\SetsCreatedBy;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
@@ -10,6 +11,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
class Library extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use SetsCreatedBy;
|
||||
|
||||
/**
|
||||
* The attributes that aren't mass assignable.
|
||||
@@ -28,15 +30,6 @@ class Library extends Model
|
||||
'language_codes' => 'array',
|
||||
];
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::creating(function ($model) {
|
||||
if (! $model->created_by) {
|
||||
$model->created_by = auth()->id();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function createdBy(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'created_by');
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Concerns\SetsCreatedBy;
|
||||
use App\Support\CustomFeedItem;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
@@ -11,7 +12,7 @@ use Illuminate\Support\Facades\Cookie;
|
||||
use Spatie\EloquentSortable\Sortable;
|
||||
use Spatie\EloquentSortable\SortableTrait;
|
||||
use Spatie\Feed\Feedable;
|
||||
use Spatie\Image\Manipulations;
|
||||
use Spatie\Image\Enums\Fit;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
||||
@@ -27,6 +28,7 @@ class LibraryItem extends Model implements Feedable, HasMedia, Sortable
|
||||
use HasStatuses;
|
||||
use HasTags;
|
||||
use InteractsWithMedia;
|
||||
use SetsCreatedBy;
|
||||
use SortableTrait;
|
||||
|
||||
/**
|
||||
@@ -60,15 +62,6 @@ class LibraryItem extends Model implements Feedable, HasMedia, Sortable
|
||||
->get();
|
||||
}
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::creating(function ($model) {
|
||||
if (! $model->created_by) {
|
||||
$model->created_by = auth()->id();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function getSlugOptions(): SlugOptions
|
||||
{
|
||||
return SlugOptions::create()
|
||||
@@ -81,13 +74,13 @@ class LibraryItem extends Model implements Feedable, HasMedia, Sortable
|
||||
{
|
||||
$this
|
||||
->addMediaConversion('preview')
|
||||
->fit(Manipulations::FIT_CROP, 300, 300)
|
||||
->fit(Fit::Crop, 300, 300)
|
||||
->nonQueued();
|
||||
$this->addMediaConversion('seo')
|
||||
->fit(Manipulations::FIT_CROP, 1200, 630)
|
||||
->fit(Fit::Crop, 1200, 630)
|
||||
->nonQueued();
|
||||
$this->addMediaConversion('thumb')
|
||||
->fit(Manipulations::FIT_CROP, 130, 130)
|
||||
->fit(Fit::Crop, 130, 130)
|
||||
->width(130)
|
||||
->height(130);
|
||||
}
|
||||
@@ -149,17 +142,4 @@ class LibraryItem extends Model implements Feedable, HasMedia, Sortable
|
||||
->link(url()->route('article.view', ['libraryItem' => $this]))
|
||||
->authorName($this->lecturer->name);
|
||||
}
|
||||
|
||||
public static function searchLibraryItems($type, $value = null)
|
||||
{
|
||||
$query = self::query()
|
||||
->where('type', $type)
|
||||
->latest('id');
|
||||
|
||||
if ($value) {
|
||||
$query->whereLike('name', "%{$value}%");
|
||||
}
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Concerns\SetsCreatedBy;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
@@ -24,6 +25,7 @@ class Meetup extends Model implements HasMedia
|
||||
use HasFactory;
|
||||
use HasSlug;
|
||||
use InteractsWithMedia;
|
||||
use SetsCreatedBy;
|
||||
|
||||
/**
|
||||
* @var array<int, string>
|
||||
@@ -120,12 +122,6 @@ class Meetup extends Model implements HasMedia
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::creating(function ($model) {
|
||||
if (! $model->created_by) {
|
||||
$model->created_by = auth()->id();
|
||||
}
|
||||
});
|
||||
|
||||
// Der Ersteller wird automatisch als Leiter in die meetup_user-Pivot eingetragen,
|
||||
// damit das Meetup einheitlich (MCP, REST-API, Livewire) in „Meine Meetups"
|
||||
// erscheint – egal über welchen Pfad es angelegt wurde.
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Models;
|
||||
|
||||
use App\Enums\RecurrenceType;
|
||||
use App\Enums\RsvpStatus;
|
||||
use App\Models\Concerns\SetsCreatedBy;
|
||||
use App\Observers\MeetupEventObserver;
|
||||
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
@@ -16,6 +17,7 @@ use Illuminate\Support\Collection;
|
||||
class MeetupEvent extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use SetsCreatedBy;
|
||||
|
||||
/**
|
||||
* The attributes that aren't mass assignable.
|
||||
@@ -47,15 +49,6 @@ class MeetupEvent extends Model
|
||||
'recurrence_type' => RecurrenceType::class,
|
||||
];
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::creating(function ($model) {
|
||||
if (! $model->created_by) {
|
||||
$model->created_by = auth()->id();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Termine, die der Nutzer bearbeiten darf: selbst angelegt ODER Leader des
|
||||
* zugehörigen Meetups (deckungsgleich mit MeetupEventPolicy::update).
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Concerns\SetsCreatedBy;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
@@ -10,6 +11,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
class Podcast extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use SetsCreatedBy;
|
||||
|
||||
/**
|
||||
* The attributes that aren't mass assignable.
|
||||
@@ -28,15 +30,6 @@ class Podcast extends Model
|
||||
'data' => 'array',
|
||||
];
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::creating(function ($model) {
|
||||
if (! $model->created_by) {
|
||||
$model->created_by = auth()->id();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function createdBy(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'created_by');
|
||||
|
||||
@@ -2,12 +2,13 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Concerns\SetsCreatedBy;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Facades\Cookie;
|
||||
use Spatie\Image\Manipulations;
|
||||
use Spatie\Image\Enums\Fit;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
||||
@@ -19,6 +20,7 @@ class ProjectProposal extends Model implements HasMedia
|
||||
use HasFactory;
|
||||
use HasSlug;
|
||||
use InteractsWithMedia;
|
||||
use SetsCreatedBy;
|
||||
|
||||
/**
|
||||
* The attributes that aren't mass assignable.
|
||||
@@ -37,15 +39,6 @@ class ProjectProposal extends Model implements HasMedia
|
||||
'user_id' => 'integer',
|
||||
];
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::creating(function ($model) {
|
||||
if (! $model->created_by) {
|
||||
$model->created_by = auth()->id();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function getSlugOptions(): SlugOptions
|
||||
{
|
||||
return SlugOptions::create()
|
||||
@@ -58,10 +51,10 @@ class ProjectProposal extends Model implements HasMedia
|
||||
{
|
||||
$this
|
||||
->addMediaConversion('preview')
|
||||
->fit(Manipulations::FIT_CROP, 300, 300)
|
||||
->fit(Fit::Crop, 300, 300)
|
||||
->nonQueued();
|
||||
$this->addMediaConversion('thumb')
|
||||
->fit(Manipulations::FIT_CROP, 130, 130)
|
||||
->fit(Fit::Crop, 130, 130)
|
||||
->width(130)
|
||||
->height(130);
|
||||
}
|
||||
|
||||
@@ -108,21 +108,11 @@ class User extends Authenticatable implements CipherSweetEncrypted
|
||||
return $this->belongsToMany(Meetup::class)->withPivot('is_leader');
|
||||
}
|
||||
|
||||
public function reputations()
|
||||
{
|
||||
return $this->morphMany('QCod\Gamify\Reputation', 'subject');
|
||||
}
|
||||
|
||||
public function votes()
|
||||
{
|
||||
return $this->hasMany(Vote::class);
|
||||
}
|
||||
|
||||
public function paidArticles()
|
||||
{
|
||||
return $this->belongsToMany(LibraryItem::class, 'library_item_user', 'user_id', 'library_item_id');
|
||||
}
|
||||
|
||||
public function updateProfilePhoto(UploadedFile $photo)
|
||||
{
|
||||
tap($this->profile_photo_path, function ($previous) use ($photo) {
|
||||
|
||||
+2
-21
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Concerns\SetsCreatedBy;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
@@ -13,14 +14,13 @@ use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
||||
use Spatie\Sluggable\HasSlug;
|
||||
use Spatie\Sluggable\SlugOptions;
|
||||
use Staudenmeir\EloquentHasManyDeep\HasRelationships;
|
||||
|
||||
class Venue extends Model implements HasMedia
|
||||
{
|
||||
use HasFactory;
|
||||
use HasRelationships;
|
||||
use HasSlug;
|
||||
use InteractsWithMedia;
|
||||
use SetsCreatedBy;
|
||||
|
||||
/**
|
||||
* The attributes that aren't mass assignable.
|
||||
@@ -39,15 +39,6 @@ class Venue extends Model implements HasMedia
|
||||
'city_id' => 'integer',
|
||||
];
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::creating(function ($model) {
|
||||
if (! $model->created_by) {
|
||||
$model->created_by = auth()->id();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function registerMediaConversions(?Media $media = null): void
|
||||
{
|
||||
$this
|
||||
@@ -88,16 +79,6 @@ class Venue extends Model implements HasMedia
|
||||
return $this->belongsTo(City::class);
|
||||
}
|
||||
|
||||
public function lecturers()
|
||||
{
|
||||
return $this->hasManyDeepFromRelations($this->courses(), (new Course)->lecturer());
|
||||
}
|
||||
|
||||
public function courses()
|
||||
{
|
||||
return $this->hasManyDeepFromRelations($this->events(), (new CourseEvent)->course());
|
||||
}
|
||||
|
||||
public function courseEvents(): HasMany
|
||||
{
|
||||
return $this->hasMany(CourseEvent::class);
|
||||
|
||||
Reference in New Issue
Block a user