diff --git a/app/Collection.php b/app/Collection.php index 2e46078c2..0905f2717 100644 --- a/app/Collection.php +++ b/app/Collection.php @@ -2,6 +2,7 @@ namespace App; +use Illuminate\Support\Str; use Illuminate\Database\Eloquent\Model; use Pixelfed\Snowflake\HasSnowflakePrimary; @@ -16,8 +17,32 @@ class Collection extends Model */ public $incrementing = false; + public $fillable = ['profile_id', 'published_at']; + public function profile() { return $this->belongsTo(Profile::class); } + + public function items() + { + return $this->hasMany(CollectionItem::class); + } + + public function posts() + { + return $this->hasManyThrough( + Status::class, + CollectionItem::class, + 'collection_id', + 'id', + 'id', + 'object_id', + ); + } + + public function url() + { + return url("/c/{$this->id}"); + } } diff --git a/app/CollectionItem.php b/app/CollectionItem.php index 0a3f72cb8..d272e68a4 100644 --- a/app/CollectionItem.php +++ b/app/CollectionItem.php @@ -9,6 +9,13 @@ class CollectionItem extends Model { use HasSnowflakePrimary; + public $fillable = [ + 'collection_id', + 'object_type', + 'object_id', + 'order' + ]; + /** * Indicates if the IDs are auto-incrementing. *