Files
Global-Jain/app/Models/Traits/Post/Relationships/PostRelationships.php
2025-11-05 10:37:10 +05:30

125 lines
2.5 KiB
PHP

<?php
namespace App\Models\Traits\Post\Relationships;
use App\Models\User;
use App\Models\Sangh;
use App\Models\Category;
use App\Models\PostImage;
use App\Models\PostComment;
use App\Models\PostHidden;
use App\Models\PostMention;
use App\Models\UserBlocked;
/**
* Trait PostRelationships
*/
trait PostRelationships
{
/**
* @return mixed
*/
public function postImages()
{
return $this->hasMany(PostImage::class, 'post_id', 'id');
}
/**
* @return mixed
*/
public function createdBy()
{
return $this->belongsTo(User::class, 'created_by', 'id');
}
/**
* @return mixed
*/
public function sanghDetails()
{
return $this->belongsTo(Sangh::class, 'type_id', 'id');
}
/**
* @return mixed
*/
public function updatedBy()
{
return $this->belongsTo(User::class, 'updated_by', 'id');
}
/**
* @return mixed
*/
public function likes()
{
return $this->belongsToMany(User::class, 'post_likes', 'post_id', 'user_id')->withTimestamps();
}
/**
* @return mixed
*/
public function tagUsers()
{
return $this->belongsToMany(User::class, 'post_tag_users', 'post_id', 'user_id')->withTimestamps();
}
/**
* @return mixed
*/
public function comments()
{
return $this->hasMany(PostComment::class, 'post_id', 'id')->whereNull('reply_id')->latest();
}
/**
* @return mixed
*/
public function category()
{
return $this->belongsTo(Category::class);
}
/**
* @return mixed
* for sangh post relationship with same naming convension for same response as other posts
*/
public function created_by()
{
return $this->belongsTo(Sangh::class, 'created_by', 'id');
}
/**
* @return mixed
* for sangh post relationship with same naming convension for same response as other posts
*/
public function updated_by()
{
return $this->belongsTo(Sangh::class, 'updated_by', 'id');
}
/**
* @return mixed
*/
public function blockedUser()
{
return $this->hasMany(UserBlocked::class, 'user_id', 'user_id');
}
/**
* @return mixed
*/
public function hiddenPost()
{
return $this->hasMany(PostHidden::class, 'post_id', 'id');
}
/**
* @return mixed
*/
public function postMention()
{
return $this->hasMany(PostMention::class, 'post_id', 'id');
}
}