Initial baseline: LaraBlog core with plugin commerce surface.
Captures the current working tree after theme slots, ArticleAccess, and the payment / paid-content plugins so subsequent work has a reviewable git history.
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Domain\Blog\ContentFormat;
|
||||
use App\Domain\Blog\ContentRenderer;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Article extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'category_id',
|
||||
'user_id',
|
||||
'title',
|
||||
'content',
|
||||
'content_format',
|
||||
'description',
|
||||
'keywords',
|
||||
'published_at',
|
||||
'views',
|
||||
'comments_count',
|
||||
'slug',
|
||||
'stick',
|
||||
'visible',
|
||||
'close_comment',
|
||||
'read_password',
|
||||
'ai_summary',
|
||||
'ai_suggestions',
|
||||
'legacy_attachments',
|
||||
'cover_disk',
|
||||
'cover_path',
|
||||
'cover_source',
|
||||
'cover_status',
|
||||
'cover_generated_at',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'published_at' => 'datetime',
|
||||
'views' => 'integer',
|
||||
'comments_count' => 'integer',
|
||||
'stick' => 'boolean',
|
||||
'visible' => 'boolean',
|
||||
'close_comment' => 'boolean',
|
||||
'ai_suggestions' => 'array',
|
||||
'legacy_attachments' => 'array',
|
||||
'cover_generated_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
public function hasCover(): bool
|
||||
{
|
||||
return $this->cover_status === 'ready' && filled($this->cover_path);
|
||||
}
|
||||
|
||||
protected function contentFormat(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn (?string $value): string => ContentFormat::normalize($value, ContentFormat::HTML),
|
||||
set: fn (?string $value): string => ContentFormat::normalize($value, ContentFormat::HTML),
|
||||
);
|
||||
}
|
||||
|
||||
public function renderedHtml(): string
|
||||
{
|
||||
return $this->rendered()['html'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{html: string, toc: list<array{level: int, id: string, text: string}>}
|
||||
*/
|
||||
public function rendered(): array
|
||||
{
|
||||
return app(ContentRenderer::class)->render(
|
||||
(string) $this->content,
|
||||
$this->content_format,
|
||||
$this->id,
|
||||
);
|
||||
}
|
||||
|
||||
public function isMarkdown(): bool
|
||||
{
|
||||
return $this->content_format === ContentFormat::MARKDOWN;
|
||||
}
|
||||
|
||||
public function category(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Category::class);
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function comments(): HasMany
|
||||
{
|
||||
return $this->hasMany(Comment::class);
|
||||
}
|
||||
|
||||
public function tags(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Tag::class);
|
||||
}
|
||||
|
||||
public function attachments(): HasMany
|
||||
{
|
||||
return $this->hasMany(Attachment::class);
|
||||
}
|
||||
|
||||
public function scopeVisible(Builder $query): Builder
|
||||
{
|
||||
return $query->where('visible', true);
|
||||
}
|
||||
|
||||
public function scopePublished(Builder $query): Builder
|
||||
{
|
||||
return $query
|
||||
->whereNotNull('published_at')
|
||||
->where('published_at', '<=', now());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Domain\Media\AttachmentStorageService;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Attachment extends Model
|
||||
{
|
||||
public const VISIBILITY_PUBLIC = 'public';
|
||||
|
||||
public const VISIBILITY_PRIVATE = 'private';
|
||||
|
||||
protected $fillable = [
|
||||
'article_id',
|
||||
'disk',
|
||||
'path',
|
||||
'thumb_path',
|
||||
'filename',
|
||||
'mime',
|
||||
'size',
|
||||
'checksum',
|
||||
'visibility',
|
||||
'legacy_filepath',
|
||||
'synced_at',
|
||||
'downloads',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'size' => 'integer',
|
||||
'downloads' => 'integer',
|
||||
'synced_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
public function article(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Article::class);
|
||||
}
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::deleting(function (Attachment $attachment): void {
|
||||
app(AttachmentStorageService::class)->deleteFromDisk($attachment);
|
||||
});
|
||||
}
|
||||
|
||||
public function scopePubliclyVisible(Builder $query): Builder
|
||||
{
|
||||
return $query->where('visibility', self::VISIBILITY_PUBLIC);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Category extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'display_order',
|
||||
'articles_count',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'display_order' => 'integer',
|
||||
'articles_count' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
public function articles(): HasMany
|
||||
{
|
||||
return $this->hasMany(Article::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Domain\Plugin\Hook;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Comment extends Model
|
||||
{
|
||||
public const STATUS_PENDING = 'pending';
|
||||
|
||||
public const STATUS_PENDING_AI = 'pending_ai';
|
||||
|
||||
public const STATUS_APPROVED = 'approved';
|
||||
|
||||
public const STATUS_REJECTED = 'rejected';
|
||||
|
||||
public const STATUS_NEEDS_HUMAN = 'needs_human';
|
||||
|
||||
protected $fillable = [
|
||||
'article_id',
|
||||
'author',
|
||||
'url',
|
||||
'content',
|
||||
'ip',
|
||||
'moderation_status',
|
||||
'published_at',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'published_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::created(function (Comment $comment): void {
|
||||
Hook::dispatch('comment.created', $comment);
|
||||
});
|
||||
}
|
||||
|
||||
public function article(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Article::class);
|
||||
}
|
||||
|
||||
public function scopeApproved(Builder $query): Builder
|
||||
{
|
||||
return $query->where('moderation_status', self::STATUS_APPROVED);
|
||||
}
|
||||
|
||||
public function scopeVisible(Builder $query): Builder
|
||||
{
|
||||
return $query->approved()
|
||||
->whereNotNull('published_at')
|
||||
->where('published_at', '<=', now());
|
||||
}
|
||||
|
||||
public function isApproved(): bool
|
||||
{
|
||||
return $this->moderation_status === self::STATUS_APPROVED;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Link extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'url',
|
||||
'note',
|
||||
'display_order',
|
||||
'visible',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'display_order' => 'integer',
|
||||
'visible' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
public function scopeVisible(Builder $query): Builder
|
||||
{
|
||||
return $query->where('visible', true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Plugin extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'version',
|
||||
'enabled',
|
||||
'path',
|
||||
'config',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'enabled' => 'boolean',
|
||||
'config' => 'array',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Stylevar extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'title',
|
||||
'value',
|
||||
'visible',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'visible' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
public function scopeVisible(Builder $query): Builder
|
||||
{
|
||||
return $query->where('visible', true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
class Tag extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'use_count',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'use_count' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
public function articles(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Article::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Support\LegacyPassword;
|
||||
use Database\Factories\UserFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Spatie\Permission\Traits\HasRoles;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
/** @use HasFactory<UserFactory> */
|
||||
use HasFactory, HasRoles, Notifiable;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'username',
|
||||
'email',
|
||||
'password',
|
||||
'password_legacy',
|
||||
'url',
|
||||
'login_count',
|
||||
'login_ip',
|
||||
'login_at',
|
||||
'reg_ip',
|
||||
'last_post_at',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'password_legacy',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
'login_count' => 'integer',
|
||||
'login_at' => 'datetime',
|
||||
'last_post_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
public function articles(): HasMany
|
||||
{
|
||||
return $this->hasMany(Article::class);
|
||||
}
|
||||
|
||||
public function attemptLegacyPasswordUpgrade(string $plainPassword): bool
|
||||
{
|
||||
if (blank($this->password_legacy)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! LegacyPassword::verify($plainPassword, $this->password_legacy)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->forceFill([
|
||||
'password' => Hash::make($plainPassword),
|
||||
'password_legacy' => null,
|
||||
])->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function hasLegacyPassword(): bool
|
||||
{
|
||||
return filled($this->password_legacy);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user