File: /home/imensosw/www/imenso.co/dev/advanchainge/app/User.php
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Spatie\Permission\Traits\HasRoles;
use Tymon\JWTAuth\Contracts\JWTSubject;
class User extends Authenticatable implements JWTSubject
{
use Notifiable,HasRoles;
const ADMIN_TYPE = 'superadmin';
const DEFAULT_TYPE = 'user';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
public function isAdmin() {
return $this->type === self::ADMIN_TYPE;
}
public function getJWTIdentifier()
{
return $this->getKey();
}
public function getJWTCustomClaims()
{
return [];
}
public static function getUserIdByCompany($companyId)
{
$result=User::where(array("type"=>"admin","companyId"=>$companyId))
->select("id")->get();
if(!empty($result))
{
return $result[0]->id;
}
return 0;
}
}