embeds()->saveMany($this->embeds); } public function user() { return $this->belongsTo(User::class); } public function embeds() { return $this->hasMany(DraftEmbed::class); } public function reply() { return $this->hasOne(Post::class, 'id', 'reply_id'); } public function isNotEmpty() { return !empty($this->title); } public function isSmallEnough() { return mb_strlen($this->title) < self::LENGTH_LIMIT && mb_strlen($this->content) < self::LENGTH_LIMIT; } public function tryFillPost() { $post = Post::where('server', $this->server) ->where('node', $this->node) ->where('nodeid', $this->nodeid) ->first(); if ($post) { $this->title = $post->title; $this->content = $post->contentraw; $this->open = $post->open; $reply = $post->getReply(); if ($reply) { $this->reply_id = $reply->id; } foreach ($post->attachments()->whereIn('rel', ['enclosure', 'related'])->get() as $attachment) { if ($attachment->category != 'embed') { $embed = new DraftEmbed; $embed->url = $attachment->href; array_push($this->embeds, $embed); } } } } }