Skip to content

Commit

Permalink
Add HasRevisions docblocks
Browse files Browse the repository at this point in the history
  • Loading branch information
pboivin authored and ifox committed Jun 28, 2021
1 parent a2a4365 commit e2b9f02
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Models/Behaviors/HasRevisions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,34 @@

trait HasRevisions
{
/**
* Defines the one-to-many relationship for revisions.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function revisions()
{
return $this->hasMany($this->getRevisionModel())->orderBy('created_at', 'desc');
}

/**
* Scope a query to only include the current user's revisions.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeMine($query)
{
return $query->whereHas('revisions', function ($query) {
$query->where('user_id', auth('twill_users')->user()->id);
});
}

/**
* Returns an array of revisions for the CMS views.
*
* @return array
*/
public function revisionsArray()
{
return $this->revisions->map(function ($revision) {
Expand Down

0 comments on commit e2b9f02

Please sign in to comment.