| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <?php
- namespace App\Models;
- /*
- * PageSection — одна секция страницы в page-builder.
- *
- * Два типа (поле type):
- * 'block' — ссылка на переиспользуемый блок (block_id → blocks)
- * 'content' — произвольный HTML-контент (поле content)
- *
- * Порядок вывода на странице задаётся sort_order.
- */
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- class PageSection extends Model
- {
- protected $fillable = ['page_id', 'type', 'content', 'block_id', 'sort_order'];
- public function page(): BelongsTo
- {
- return $this->belongsTo(Page::class);
- }
- public function block(): BelongsTo
- {
- return $this->belongsTo(Block::class);
- }
- // Возвращает HTML для рендера на публичной странице
- public function getRenderedContent(): string
- {
- if ($this->type === 'content') {
- return (string) $this->content;
- }
- if ($this->block && $this->block->is_active) {
- return $this->block->render();
- }
- return '';
- }
- }
|