Skip to content

Commit

Permalink
Merge pull request #86 from musimana/feature/CreateHasContentBlocks
Browse files Browse the repository at this point in the history
feat: Create HasContentBlocks Trait
  • Loading branch information
musimana authored Jun 2, 2024
2 parents a0731e8 + bc36ce0 commit a3571d0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
21 changes: 21 additions & 0 deletions app/Traits/HasContentBlocks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Traits;

use App\Models\Block;
use Illuminate\Database\Eloquent\Relations\HasMany;

trait HasContentBlocks
{
/**
* The relationship for the resource's content blocks.
*
* @return HasMany<Block>
*/
public function blocks(): HasMany
{
return $this->hasMany(Block::class, 'parent_id')
->where('parent_type', self::class)
->orderBy('display_order');
}
}
17 changes: 2 additions & 15 deletions app/Traits/HasPageView.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

namespace App\Traits;

use App\Models\Block;
use Illuminate\Database\Eloquent\Relations\HasMany;

trait HasPageView
{
use HasContentBlocks;

/** Get the meta-description for the resource. */
public function getMetaDescription(): string
{
Expand Down Expand Up @@ -36,16 +35,4 @@ public function isInSitemap(): bool
{
return $this->in_sitemap ?? false;
}

/**
* The relationship for the resource's content blocks.
*
* @return HasMany<Block>
*/
public function blocks(): HasMany
{
return $this->hasMany(Block::class, 'parent_id')
->where('parent_type', self::class)
->orderBy('display_order');
}
}

0 comments on commit a3571d0

Please sign in to comment.