Make tables smaller
This commit is contained in:
parent
9e2babb298
commit
941ef99d32
4 changed files with 70 additions and 4 deletions
|
|
@ -9,9 +9,7 @@ public function up(): void {
|
|||
Capsule::schema()->create('articles', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('url')->unique();
|
||||
$table->string('title')->nullable();
|
||||
$table->json('data')->nullable();
|
||||
$table->timestamp('seen_at')->useCurrent();
|
||||
$table->timestamp('created_at')->useCurrent();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ public function up(): void {
|
|||
$table->foreignId('article_id')->constrained('articles')->onDelete('cascade');
|
||||
$table->string('community');
|
||||
$table->timestamp('posted_at')->useCurrent();
|
||||
$table->json('response')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
39
src/Domain/Articles/Article.php
Normal file
39
src/Domain/Articles/Article.php
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace Domain\Articles;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Article extends Model
|
||||
{
|
||||
protected $table = 'articles';
|
||||
|
||||
protected $fillable = [
|
||||
'url',
|
||||
'title',
|
||||
'data',
|
||||
'seen_at',
|
||||
];
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
protected $casts = [
|
||||
'seen_at' => 'datetime',
|
||||
'data' => 'array',
|
||||
];
|
||||
|
||||
public function posts(): HasMany
|
||||
{
|
||||
return $this->hasMany(ArticlePosted::class);
|
||||
}
|
||||
|
||||
public function publish(string $community = 'default'): void
|
||||
{
|
||||
ArticlePosted::create([
|
||||
'article_id' => $this->id,
|
||||
'community' => $community,
|
||||
'posted_at' => now(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
30
src/Domain/Articles/ArticlePosted.php
Normal file
30
src/Domain/Articles/ArticlePosted.php
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace Domain\Articles;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class ArticlePosted extends Model
|
||||
{
|
||||
protected $table = 'article_posted';
|
||||
|
||||
protected $fillable = [
|
||||
'article_id',
|
||||
'community',
|
||||
'posted_at',
|
||||
'response',
|
||||
];
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
protected $casts = [
|
||||
'posted_at' => 'datetime',
|
||||
'response' => 'array',
|
||||
];
|
||||
|
||||
public function article(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Article::class);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue