2024-03-28 14:52:40 +05:30
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
|
|
|
use Illuminate\Notifications\Notifiable;
|
|
|
|
|
use Laravel\Sanctum\HasApiTokens;
|
|
|
|
|
use App\Models\MonthlyUpdateMaster;
|
|
|
|
|
|
|
|
|
|
use Auth;
|
|
|
|
|
// IAM Module Model
|
|
|
|
|
use App\Models\Permission;
|
|
|
|
|
use App\Models\Role;
|
|
|
|
|
use App\Models\Admin\PrincipalRoleLink;
|
|
|
|
|
use App\Models\Admin\AppResource;
|
|
|
|
|
use App\Models\Admin\AppResourceAction;
|
|
|
|
|
use App\Models\Admin\RoleAppResouceActionLink;
|
|
|
|
|
// END
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
|
|
|
|
|
|
class User extends Authenticatable implements MustVerifyEmail
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
use HasApiTokens,
|
|
|
|
|
HasFactory,
|
|
|
|
|
Notifiable,
|
|
|
|
|
SoftDeletes;
|
|
|
|
|
|
|
|
|
|
public $timestamps = true;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The attributes that are mass assignable.
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'name',
|
|
|
|
|
'authorized_representative_name',
|
|
|
|
|
'first_name',
|
|
|
|
|
'last_name',
|
|
|
|
|
'email',
|
|
|
|
|
'contact_number',
|
|
|
|
|
'password',
|
|
|
|
|
'role',
|
|
|
|
|
'user_type',
|
|
|
|
|
'otp',
|
|
|
|
|
'is_verify',
|
|
|
|
|
'last_login',
|
|
|
|
|
'profile_image',
|
|
|
|
|
'pin'
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The attributes that should be hidden for arrays.
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $hidden = [
|
|
|
|
|
'remember_token',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The attributes that should be cast to native types.
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $casts = [
|
|
|
|
|
'email_verified_at' => 'datetime',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const ADMIN = 1;
|
|
|
|
|
|
|
|
|
|
public function manyRoles()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(PrincipalRoleLink::class);
|
|
|
|
|
}
|
2024-04-09 17:56:07 +05:30
|
|
|
public function getAppResourcesActionLink()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Iam_App_Resource_Action_Link::class, 'user_xid', 'id');
|
|
|
|
|
}
|
2024-03-28 14:52:40 +05:30
|
|
|
|
2024-04-09 17:56:07 +05:30
|
|
|
public function checkRoleWithPermission($resource, $permission = null)
|
2024-03-28 14:52:40 +05:30
|
|
|
{
|
2024-04-09 17:56:07 +05:30
|
|
|
// dd(\Auth::user()->id);
|
2024-05-28 15:55:59 +05:30
|
|
|
$user = User::with('getAppResourcesActionLink')->where('id', \Auth::user()->id)->where('status',true)->first();
|
2024-04-09 17:56:07 +05:30
|
|
|
$sidebarSlugs = array();
|
|
|
|
|
foreach ($user->getAppResourcesActionLink as $userResource) {
|
|
|
|
|
$resourceSlug = Iam_App_Resources::find($userResource->app_resource_xid);
|
|
|
|
|
array_push($sidebarSlugs, $resourceSlug->slug);
|
2024-03-28 14:52:40 +05:30
|
|
|
}
|
2024-04-09 17:56:07 +05:30
|
|
|
if (in_array($resource, $sidebarSlugs) || $user->role == 1) {
|
2024-03-28 14:52:40 +05:30
|
|
|
return true;
|
2024-04-09 17:56:07 +05:30
|
|
|
} else {
|
|
|
|
|
return false;
|
2024-03-28 14:52:40 +05:30
|
|
|
}
|
2024-04-09 17:56:07 +05:30
|
|
|
// return true;
|
|
|
|
|
// $checkRole = User::with('manyRoles.roles')->where('id', \Auth::user()->id)->get();
|
|
|
|
|
// $totalRolesAssigned = array();
|
|
|
|
|
// foreach ($checkRole as $data) {
|
|
|
|
|
// foreach ($data->manyRoles as $role) {
|
|
|
|
|
// array_push($totalRolesAssigned, $role->roles->slug);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// if (in_array('super-admin', $totalRolesAssigned)) {
|
|
|
|
|
// return true;
|
|
|
|
|
// }
|
|
|
|
|
// foreach ($totalRolesAssigned as $slug) {
|
|
|
|
|
// $roleData = Role::where('slug', $slug)->first();
|
|
|
|
|
// if ($roleData) {
|
|
|
|
|
// $appResource = AppResource::where('slug', $resource)->first();
|
|
|
|
|
// $permission = Permission::where('slug', $permission)->first();
|
|
|
|
|
// if ($appResource && $permission) {
|
|
|
|
|
// $appResourceAction = AppResourceAction::where('app_resource_xid', $appResource->id)->where('app_action_xid', $permission->id)->first();
|
|
|
|
|
// if ($appResourceAction) {
|
|
|
|
|
// $isRoleLinkWithResource = RoleAppResouceActionLink::where('app_resource_action_xid', $appResourceAction->id)->where('role_xid', $roleData->id)->exists();
|
|
|
|
|
// if ($isRoleLinkWithResource) {
|
|
|
|
|
// return true;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// return false;
|
2024-03-28 14:52:40 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function scopeAdmins(Builder $query): void
|
|
|
|
|
{
|
|
|
|
|
$query->where('role', 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function scopeUsers(Builder $query): void
|
|
|
|
|
{
|
|
|
|
|
$query->where('role', false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function scopeActive(Builder $query): void
|
|
|
|
|
{
|
|
|
|
|
$query->where('status', true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// const path = 'https://jerichoalternatives.in/public/uploads/profile/img/';
|
|
|
|
|
|
|
|
|
|
public function getProfileImageAttribute($value)
|
|
|
|
|
{
|
|
|
|
|
if ($value)
|
|
|
|
|
return imagePath('public/uploads/profile/img/') . $value;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-09 17:56:07 +05:30
|
|
|
public function activeInvestments()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(MonthlyUpdateMaster::class, 'users_id')->where('holding_status', 'Holding');
|
2024-03-28 14:52:40 +05:30
|
|
|
}
|
|
|
|
|
|
2024-04-09 17:56:07 +05:30
|
|
|
public function investments()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(MonthlyUpdateMaster::class, 'users_id');
|
2024-03-28 14:52:40 +05:30
|
|
|
}
|
|
|
|
|
|
2024-04-09 17:56:07 +05:30
|
|
|
public function total()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Chat::class, 'user_id')->where(['by' => 'User', 'read_at' => null]);
|
2024-03-28 14:52:40 +05:30
|
|
|
}
|
|
|
|
|
}
|