| Server IP : 46.62.235.243 / Your IP : 216.73.216.217 Web Server : Apache/2.4.58 (Ubuntu) System : Linux Linkabili3Dicembre 6.8.0-100-generic #100-Ubuntu SMP PREEMPT_DYNAMIC Tue Jan 13 16:40:06 UTC 2026 x86_64 User : www-data ( 33) PHP Version : 8.1.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/linkabili/app/ |
Upload File : |
<?php
namespace App;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\Notifications\VerifyEmail;
use App\Notifications\MyResetPassword;
use Laravel\Sanctum\HasApiTokens;
use DB;
class User extends Authenticatable implements MustVerifyEmail {
use SoftDeletes,
Notifiable,
HasApiTokens;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password', 'active', 'surname', 'path_url', 'accept_privacy_police','accept_commercial','accept_terms','path_cv',"gender","id_azienda"
];
/**
* 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 isActive($role = 'professionist') {
$user = \Auth::user();
if ($user && ($user->active == 1 || $user->active == 'on')) {
return true;
}
return false;
}
public function checkRole($role = 'professionist') {
$user = \Auth::user();
if ($user && $user->user_type == $role) {
return true;
}
return false;
}
public function isAdmin() {
$user = \Auth::user();
if ($user && $user->user_type == 'admin') {
return true;
}
return false;
}
public function isProfessionista() {
$user = \Auth::user();
if ($user && $user->user_type == 'professionist') {
return true;
}
return false;
}
public function isHR() {
$user = \Auth::user();
if ($user && $user->user_type == 'hr') {
return true;
}
return false;
}
public function isCareGivers() {
$user = \Auth::user();
if ($user && $user->user_type == 'care_giver') {
return true;
}
return false;
}
public function isMedicalCenter() {
$user = \Auth::user();
if ($user && $user->user_type == 'medical_center') {
return true;
}
return false;
}
public function isOtherIstitution() {
$user = \Auth::user();
if ($user && $user->user_type == 'other_istitution') {
return true;
}
return false;
}
// public function sendEmailVerificationNotification() {
// $this->notify(new VerifyEmail);
// }
public function user_details() {
return $this->hasOne('App\Models\UserDetail', 'user_id', 'id');
}
public function professions() {
return $this->belongsToMany('App\Models\Profession', 'user_profession', 'user_id', 'profession_id');
}
public function pathologies() {
return $this->belongsToMany('App\Models\Pathology', 'user_pathology', 'user_id', 'pathology_id');
}
public function professions_md() {
return $this->belongsToMany('App\Models\Profession', 'user_profession', 'user_id', 'profession_id');
}
public function pathologies_md() {
return $this->belongsToMany('App\Models\Pathology', 'user_pathology', 'user_id', 'pathology_id');
}
public function services() {
return $this->belongsToMany('App\Models\Service', 'user_service', 'user_id', 'service_id');
}
public function certifications() {
return $this->belongsToMany('App\Models\Certification', 'user_certification', 'user_id', 'certification_id')->withPivot('path_name');
}
public function documents() {
return $this->belongsToMany('App\Models\Document', 'user_document', 'user_id', 'document_id')->withPivot(['id','path_name', 'month', 'year']);
}
public function states() {
return $this->belongsToMany('App\Models\State', 'user_state', 'user_id', 'state_id');
}
public function medicalcenter() {
return $this->user_details->medicalcenter();
}
public function professionalstudies() {
return $this->hasMany('App\Models\ProfessionalStudy');
}
public function collaborations() {
return $this->belongsToMany('App\Models\Collaboration','collaborations','user_id','collaboration_id');
}
public function other_study() {
return $this->hasMany('App\Models\OtherStudy');
}
public function registers() {
return $this->hasMany('App\Models\Register');
}
public function specialiazation() {
return $this->belongsToMany('App\Models\ProfessionSpecialization', 'user_professionspecialization', 'user_id', 'prof_speci_id');
}
public function specialiazationcenter() {
return $this->belongsToMany('App\Models\MedicalCenterSpecialization', 'user_med_spec', 'user_id', 'medical_speci_id');
}
public function referenze() {
return $this->hasMany('App\Models\UserReferenze', 'user_id');
}
public function referenzeVerificate() {
return $this->hasMany('App\Models\UserReferenze', 'user_id')->where('verificato', 1);
}
public function sendEmailVerificationNotification() {
$this->notify(new VerifyEmail); // my notification
}
public function sendPasswordResetNotification($token) {
$this->notify(new MyResetPassword($token));
}
public function reviewsValidated() {
return $this->reviews()->where('validated', 1)->count();
}
public function reviews() {
return $this->hasMany('App\Models\Review', 'to_id');
}
public function getRatingAvgAttribute() {
return $this->reviewsValidated() ? round($this->reviews->where('validated', 1)->sum('rating') / $this->reviewsValidated(), 1) : 0;
}
public function getRating1AvgAttribute() {
return $this->reviewsValidated() ? round($this->reviews->where('validated', 1)->avg('rating_1'), 1) : 0;
}
public function getRating2AvgAttribute() {
return $this->reviewsValidated() ? round($this->reviews->where('validated', 1)->avg('rating_2'), 1) : 0;
}
public function getRating3AvgAttribute() {
return $this->reviewsValidated() ? round($this->reviews->where('validated', 1)->avg('rating_3'), 1) : 0;
}
public function getRating4AvgAttribute() {
return $this->reviewsValidated() ? round($this->reviews->where('validated', 1)->avg('rating_4'), 1) : 0;
}
public function setSlug() {
$counter = 0;
$name = (in_array($this->user_type, ['medical_center', 'other_istitution']) ? $this->user_details->business_name ?? null : null) ?: $this->name . "-" . $this->surname;
do {
$slug = slugify($name) . ($counter > 0 ? "-$counter" : "");
$counter++;
}
while (!!User::where('slug', $slug)->where('id', '<>', $this->id)->first());
$this->slug = substr($slug, 0, 50);
$this->save();
}
public function getCanBeReviewedAttribute() {
$user = \Auth::user();
return $this->id !== $user->id && $this->getHasBeenContactedAttribute() && !$this->reviews()->where('from_id', $user->id)->first();
}
public function getHasBeenContactedAttribute() {
$user = \Auth::user();
return !!($user && DB::table('ch_messages')
->where('from_id', $user->id)
->where('to_id', $this->id)
->orWhere( function ($query) use ($user) {
$query ->where('to_id', $user->id)
->where('from_id', $this->id);
})
->first());
}
}