forked from eatvio/eatvio-infra
04 10 2023 snapshot
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
/* use Illuminate\Database\Eloquent\Builder; */
|
||||
@@ -26,8 +27,15 @@ class BlogPost extends Model implements Viewable
|
||||
|
||||
public function author()
|
||||
{
|
||||
/* return $this->belongsToMany(User::class, 'blog_post_author', 'blog_post_id', 'user_id'); */
|
||||
return $this->hasOneThrough(User::class, BlogPostAuthor::class, 'blog_post_id', 'id', 'id', 'user_id');
|
||||
return $this
|
||||
->hasOneThrough(User::class, BlogPostAuthor::class, 'blog_post_id', 'id', 'id', 'user_id')
|
||||
->withDefault(
|
||||
[
|
||||
'name' => 'Guest Author',
|
||||
'id' => 0,
|
||||
'profile_photo_url' => 'https://dev2.eatvio.com/storage/profile-photos/mW87tqy9P8O31Dauyvg8f7GowMNMsgt9J6u47T7S.jpg'
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function comments()
|
||||
@@ -60,6 +68,10 @@ class BlogPost extends Model implements Viewable
|
||||
return false;
|
||||
}
|
||||
|
||||
public function scopeNoEagerLoads($query) {
|
||||
return $query->setEagerLoads([]);
|
||||
}
|
||||
|
||||
public function scopeContainsTag($query, $tagString): Builder
|
||||
{
|
||||
$tagId = Str::of($tagString)->split('/-/')->first();
|
||||
|
||||
Reference in New Issue
Block a user