login update

This commit is contained in:
2026-03-05 11:24:37 +01:00
parent 5a33ca55a1
commit f6772f673b
67 changed files with 10640 additions and 116 deletions

View File

@@ -0,0 +1,24 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class SocialAccount extends Model
{
protected $table = 'social_accounts';
protected $fillable = [
'user_id',
'provider',
'provider_id',
'provider_email',
'avatar',
];
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
}

113
app/Models/Story.php Normal file
View File

@@ -0,0 +1,113 @@
<?php
declare(strict_types=1);
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
/**
* Story editorial content replacing the legacy Interviews module.
*
* @property int $id
* @property string $slug
* @property string $title
* @property string|null $excerpt
* @property string|null $content
* @property string|null $cover_image
* @property int|null $author_id
* @property int $views
* @property bool $featured
* @property string $status draft|published
* @property \Carbon\Carbon|null $published_at
* @property int|null $legacy_interview_id
*/
class Story extends Model
{
use HasFactory;
protected $table = 'stories';
protected $fillable = [
'slug',
'title',
'excerpt',
'content',
'cover_image',
'author_id',
'views',
'featured',
'status',
'published_at',
'legacy_interview_id',
];
protected $casts = [
'featured' => 'boolean',
'published_at' => 'datetime',
'views' => 'integer',
];
// ── Relations ────────────────────────────────────────────────────────
public function author()
{
return $this->belongsTo(StoryAuthor::class, 'author_id');
}
public function tags()
{
return $this->belongsToMany(StoryTag::class, 'stories_tag_relation', 'story_id', 'tag_id');
}
// ── Scopes ───────────────────────────────────────────────────────────
public function scopePublished($query)
{
return $query->where('status', 'published')
->where(fn ($q) => $q->whereNull('published_at')->orWhere('published_at', '<=', now()));
}
public function scopeFeatured($query)
{
return $query->where('featured', true);
}
// ── Accessors ────────────────────────────────────────────────────────
public function getUrlAttribute(): string
{
return url('/stories/' . $this->slug);
}
public function getCoverUrlAttribute(): ?string
{
if (! $this->cover_image) {
return null;
}
return str_starts_with($this->cover_image, 'http') ? $this->cover_image : asset($this->cover_image);
}
/**
* Estimated reading time in minutes based on word count.
*/
public function getReadingTimeAttribute(): int
{
$wordCount = str_word_count(strip_tags((string) $this->content));
return max(1, (int) ceil($wordCount / 200));
}
/**
* Short excerpt for meta descriptions / cards.
* Strips HTML, truncates to ~160 characters.
*/
public function getMetaExcerptAttribute(): string
{
$text = $this->excerpt ?: strip_tags((string) $this->content);
return \Illuminate\Support\Str::limit($text, 160);
}
}

View File

@@ -0,0 +1,63 @@
<?php
declare(strict_types=1);
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
/**
* Story Author - flexible author entity for the Stories system.
*
* @property int $id
* @property int|null $user_id
* @property string $name
* @property string|null $avatar
* @property string|null $bio
*/
class StoryAuthor extends Model
{
use HasFactory;
protected $table = 'stories_authors';
protected $fillable = [
'user_id',
'name',
'avatar',
'bio',
];
// ── Relations ────────────────────────────────────────────────────────
public function user()
{
return $this->belongsTo(User::class);
}
public function stories()
{
return $this->hasMany(Story::class, 'author_id');
}
// ── Accessors ────────────────────────────────────────────────────────
public function getAvatarUrlAttribute(): string
{
if ($this->avatar) {
return str_starts_with($this->avatar, 'http') ? $this->avatar : asset($this->avatar);
}
return asset('gfx/default-avatar.png');
}
public function getProfileUrlAttribute(): string
{
if ($this->user) {
return url('/@' . $this->user->username);
}
return url('/stories');
}
}

41
app/Models/StoryTag.php Normal file
View File

@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
/**
* Story Tag editorial tag for the Stories system.
*
* @property int $id
* @property string $slug
* @property string $name
*/
class StoryTag extends Model
{
use HasFactory;
protected $table = 'stories_tags';
protected $fillable = [
'slug',
'name',
];
// ── Relations ────────────────────────────────────────────────────────
public function stories()
{
return $this->belongsToMany(Story::class, 'stories_tag_relation', 'tag_id', 'story_id');
}
// ── Accessors ────────────────────────────────────────────────────────
public function getUrlAttribute(): string
{
return url('/stories/tag/' . $this->slug);
}
}

View File

@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\HasMany;
use App\Models\SocialAccount;
use App\Models\Conversation;
use App\Models\ConversationParticipant;
use App\Models\Message;
@@ -76,6 +77,11 @@ class User extends Authenticatable
return $this->hasMany(Artwork::class);
}
public function socialAccounts(): HasMany
{
return $this->hasMany(SocialAccount::class);
}
public function profile(): HasOne
{
return $this->hasOne(UserProfile::class, 'user_id');