3838 * This is not a database model in itself but extended.
3939 *
4040 * @property int $id
41+ * @property string $type
4142 * @property string $name
4243 * @property string $slug
4344 * @property Carbon $created_at
@@ -123,8 +124,8 @@ public function scopeVisible(Builder $query): Builder
123124 public function scopeWithLastView (Builder $ query )
124125 {
125126 $ viewedAtQuery = View::query ()->select ('updated_at ' )
126- ->whereColumn ('viewable_id ' , '= ' , $ this -> getTable () . ' .id ' )
127- ->where ('viewable_type ' , '= ' , $ this -> getMorphClass () )
127+ ->whereColumn ('viewable_id ' , '= ' , ' entities .id ' )
128+ ->whereColumn ('viewable_type ' , '= ' , ' entities.type ' )
128129 ->where ('user_id ' , '= ' , user ()->id )
129130 ->take (1 );
130131
@@ -134,11 +135,12 @@ public function scopeWithLastView(Builder $query)
134135 /**
135136 * Query scope to get the total view count of the entities.
136137 */
137- public function scopeWithViewCount (Builder $ query )
138+ public function scopeWithViewCount (Builder $ query ): void
138139 {
139140 $ viewCountQuery = View::query ()->selectRaw ('SUM(views) as view_count ' )
140- ->whereColumn ('viewable_id ' , '= ' , $ this ->getTable () . '.id ' )
141- ->where ('viewable_type ' , '= ' , $ this ->getMorphClass ())->take (1 );
141+ ->whereColumn ('viewable_id ' , '= ' , 'entities.id ' )
142+ ->whereColumn ('viewable_type ' , '= ' , 'entities.type ' )
143+ ->take (1 );
142144
143145 $ query ->addSelect (['view_count ' => $ viewCountQuery ]);
144146 }
@@ -194,7 +196,8 @@ public function views(): MorphMany
194196 */
195197 public function tags (): MorphMany
196198 {
197- return $ this ->morphMany (Tag::class, 'entity ' )->orderBy ('order ' , 'asc ' );
199+ return $ this ->morphMany (Tag::class, 'entity ' )
200+ ->orderBy ('order ' , 'asc ' );
198201 }
199202
200203 /**
@@ -216,7 +219,7 @@ public function searchTerms(): MorphMany
216219 }
217220
218221 /**
219- * Get this entities restrictions .
222+ * Get this entities assigned permissions .
220223 */
221224 public function permissions (): MorphMany
222225 {
@@ -299,7 +302,7 @@ public static function getType(): string
299302 }
300303
301304 /**
302- * Gets a limited-length version of the entities name.
305+ * Gets a limited-length version of the entity name.
303306 */
304307 public function getShortName (int $ length = 25 ): string
305308 {
@@ -338,7 +341,7 @@ public function getParent(): ?self
338341 {
339342 if ($ this instanceof Page) {
340343 /** @var BelongsTo<Chapter|Book, Page> $builder */
341- $ builder = $ this ->chapter_id ? $ this ->chapter () : $ this ->book ();
344+ $ builder = $ this ->pageData -> chapter_id ? $ this ->chapter () : $ this ->book ();
342345 return $ builder ->withTrashed ()->first ();
343346 }
344347 if ($ this instanceof Chapter) {
0 commit comments