api code global jain

This commit is contained in:
Abhishek Mali
2025-11-05 10:37:10 +05:30
commit 52fe7e2bec
2834 changed files with 1784903 additions and 0 deletions

View File

@@ -0,0 +1,116 @@
<?php
namespace App\Models\Traits\Post\Attributes;
use App\Models\User;
use App\Models\Request;
use App\Constant\Constant;
use App\Models\PostMention;
use App\Models\Sangh;
use App\Models\Sant;
use App\Traits\ActionButtons;
trait PostAttributes
{
use ActionButtons;
/**
* Returns request sent status.
*/
public function getIsFriendsAttribute()
{
$receiver = Request::where([
'receiver_id' => loggedInUser()->id,
'sender_id' => $this->created_by,
'status' => Constant::STATUS_ONE
])->first();
$sender = Request::where([
'receiver_id' => $this->created_by,
'sender_id' => loggedInUser()->id,
'status' => Constant::STATUS_ONE
])->first();
if ($receiver || $sender) {
return Constant::STATUS_TRUE;
} else {
return Constant::STATUS_FALSE;
}
}
/**
* Returns user's liked status.
*/
public function getIsLikedAttribute()
{
$user = loggedInUser();
if ($this->likes->contains($user->id)) {
return Constant::STATUS_TRUE;
} else {
return Constant::STATUS_FALSE;
}
}
/**
* Returns user's liked status.
*/
public function getPostTypeAttribute()
{
if ($this->category_id == Constant::STATUS_ONE) {
return 'Dharmik';
} else if ($this->category_id == Constant::STATUS_TWO) {
return 'Accomplishment';
} else if ($this->category_id == Constant::STATUS_THREE) {
return 'Announcement';
} else if ($this->category_id == Constant::STATUS_FOUR) {
return 'Celebration';
} else if ($this->category_id == Constant::STATUS_FIVE) {
return 'General';
}
}
/**
* Returns post's mentions.
*/
public function getMentionsAttribute()
{
$postMentions = PostMention::where('post_id', $this->id)->get()->toArray();
$data = [];
foreach ($postMentions as $postMention) {
if (!empty($postMention) && $postMention['type'] == Constant::STATUS_ONE) {
$user = User::where('id', $postMention['mention_id'])->first();
$data[] = [
'id' => $user->id,
'name' => $user->name,
'type' => 'user'
];
}
if (!empty($postMention) && $postMention['type'] == Constant::STATUS_TWO) {
$sant = Sant::where('id', $postMention['mention_id'])->first();
$data[] = [
'id' => $sant->id,
'name' => $sant->name,
'type' => 'sant'
];
}
if (!empty($postMention) && $postMention['type'] == Constant::STATUS_THREE) {
$sangh = Sangh::where('id', $postMention['mention_id'])->first();
$data[] = [
'id' => $sangh->id,
'name' => $sangh->name,
'type' => 'sangh'
];
}
}
return $data;
}
}