You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
willaengine/app/User.php

211 lines
5.2 KiB

<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Spatie\Permission\Traits\HasRoles;
use Laravel\Passport\HasApiTokens;
use App\Appended\Traites\GetDateAttributesTrait;
use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;
use Carbon\Carbon;
class User extends Authenticatable
{
// use Notifiable, HasRoles, HasApiTokens;
// use GetDateAttributesTrait;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'email',
'password',
'cell_number',
'business_id',
'introducer_id',
'last_used_business',
'email_token',
'birthday',
'detail'
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
////////////////////////////////////////////// new added /////////////////////////
//
// public function cachedRoles()
// {
// /*$userPrimaryKey = $this->primaryKey;
//
// return Cache::remember($cacheKey, 10, function () {
// return $this->roles()->get();
// }*/
// return $this->roles()->get();
//
// }
//
public function canDo($permission, $requireAll = false)
{
if (is_array($permission)) {
foreach ($permission as $permName) {
$hasPerm = $this->canDo($permName);
if ($hasPerm && !$requireAll) {
return true;
} elseif (!$hasPerm && $requireAll) {
return false;
}
}
return $requireAll;
} else {
foreach ($this->cachedRoles() as $role) {
// Validate against the Permission table
foreach ($role->cachedPermissions() as $perm) {
if (strtolower($permission) == strtolower($perm->title)) {
return true;
}
}
}
}
return false;
}
//
// public function hasRole($name)
// {
// foreach ($this->roles()->get() as $role)
// {
// if (strtolower($role->title)===strtolower($name))
// {
// return true;
// }
// }
// return false;
// }
///////////////////////////////////////////////////////////////////
public function images()
{
return $this->morphToMany('App\Gallery', 'uploadable');
}
public function offers()
{
return $this->hasMany('App\Offer');
}
public function shopping_carts()
{
return $this->hasMany('App\ShoppingCart');
}
public function businesses()
{
return $this->hasMany('App\Business');
}
public function business_items()
{
return $this->hasMany('App\BusinessItem');
}
public function feedbacks()
{
return $this->hasMany('App\Feedback');
}
public function active_business()
{
return $this->belongsTo('App\Business', 'last_used_business');
}
public function buys()
{
return $this->hasMany('App\Order', 'buyer_id');
}
public function sells()
{
return $this->hasMany('App\Order', 'seller_id');
}
public function files()
{
return $this->hasMany('App\Gallery')->where('business_id', null);
}
public function orginalProfile()
{
return $this->morphToMany('App\Gallery', 'uploadable')->wherePivot('image_role', 'Profile')->where('parent_id', null);
}
public function Profile()
{
return $this->morphToMany('App\Gallery', 'uploadable')->wherePivot('image_role', 'Profile')->where('parent_id', null);
}
public function addresses()
{
return $this->morphMany('App\Address', 'addressable');
}
public function introducer()
{
return $this->belongsTo('App\User', 'introducer_id', 'id');
}
public function send_conversations()
{
return $this->hasMany('App\Conversation', 'sender_id');
}
public function recieve_conversations()
{
return $this->hasMany('App\Conversation', 'receiver_id');
}
public function reservations()
{
return $this->hasMany('App\Reservation');
}
public function likes()
{
return $this->hasMany('App\Like');
}
// public function files()
// {
// return $this->hasMany()
// }
public static function MakeDetail(){
return json_encode (['NationalCode' , 'ParentName' , 'Educational' , 'PlaceBirth']);
}
public function setBirthdayAttribute($value)
{
$carbon = new Carbon();
$date = substr($value, 0, -3);
$date = $carbon->timestamp($date)->timezone('Asia/Tehran')->toDateString();
$this->attributes['birthday'] = $date;
}
public function frames()
{
return $this->belongsToMany('App\\SpFrame', 'sp_frame_user')->withPivot('action')->withTimestamps();
}
}