Skip to content

Commit

Permalink
Add HasBlocks docblocks for public methods
Browse files Browse the repository at this point in the history
  • Loading branch information
pboivin authored and ifox committed Jun 28, 2021
1 parent 36a695c commit 3adddbe
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Models/Behaviors/HasBlocks.php
Expand Up @@ -6,11 +6,24 @@

trait HasBlocks
{
/**
* Defines the one-to-many relationship for block objects.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function blocks()
{
return $this->morphMany(Block::class, 'blockable')->orderBy(config('twill.blocks_table', 'twill_blocks') . '.position', 'asc');
}

/**
* Returns the rendered Blade views for all attached blocks in their proper order.
*
* @param bool $renderChilds Include all child blocks in the rendered output.
* @param array $blockViewMappings Provide alternate Blade views for blocks. Format: `['block-type' => 'view.path']`.
* @param array $data Provide extra data to Blade views.
* @return string
*/
public function renderBlocks($renderChilds = true, $blockViewMappings = [], $data = [])
{
return $this->blocks->where('parent_id', null)->map(function ($block) use ($blockViewMappings, $renderChilds, $data) {
Expand Down

0 comments on commit 3adddbe

Please sign in to comment.