Файловый менеджер - Редактировать - /home/clickysoft/public_html/travel-guru.clickysoft.net/app/Models/User.php
Назад
<?php namespace App\Models; use App\Notifications\PasswordResetNotification; use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Hash; use Laravel\Sanctum\HasApiTokens; use Spatie\Permission\Traits\HasRoles; use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\InteractsWithMedia; class User extends Authenticatable implements HasMedia, MustVerifyEmail { use HasApiTokens, HasFactory, Notifiable, HasRoles, InteractsWithMedia; protected $table = 'users'; const ROLES = [ 'Admin' ]; const ADMIN = 'Admin'; /** * The attributes that are mass assignable. * * @var array<int, string> */ protected $fillable = [ 'full_name', 'email', 'password', 'profile_image', 'verification_code', 'is_verified', 'is_active', 'user_name', 'years_of_experience', 'summary', 'phone_number', 'languages', 'country', 'uuid' ]; /** * The attributes that should be hidden for serialization. * * @var array<int, string> */ protected $hidden = [ 'password', // 'remember_token', ]; protected $casts = [ 'last_seen' => 'datetime', // Other casts... ]; protected function password(): Attribute { return Attribute::make( set: fn ($value) => Hash::make($value), ); } public function registerMediaCollections(): void { $this->addMediaCollection('profile_photo'); } // protected function profileImage(): Attribute // { // return Attribute::make( // get: fn ($value) => !empty($value) ? $value : '/front/images/user.png', // ); // } public function sendPasswordResetNotification($token) { $this->notify(new PasswordResetNotification($token, $this->email)); } public function getPlaceholderAvatarUrl($name) { $name = urlencode($name); return "https://ui-avatars.com/api/?name={$name}&background=random&size=300"; } public function badges() { return $this->belongsToMany(Badge::class, 'badge_user'); } public function totalReviews() { return $this->userReviews()->count(); } public function averageRating(): Attribute { return Attribute::make( get: fn () => $this->userReviews()->avg('rating') ?: 0, ); } public function userReviews() { return $this->hasMany(UserReview::class, 'agent_id'); } public function reviewsGiven() { return $this->hasMany(UserReview::class, 'user_id'); } public function scopeWithAverageRating($query) { return $query->withAvg('userReviews', 'rating'); } public function scopeTopRatedAgents($query, $limit = 8) { // Fetch agents with their average rating, default to 0 for agents without reviews return $query->withAvg('userReviews', 'rating') // Calculate average rating ->where('users.is_active', true) ->whereNotNull('users.email_verified_at') ->orderByDesc('user_reviews_avg_rating') // Sort by average rating ->take($limit); } // public function scopeTopRatedAgents($query, $limit = 8) // { // return $query->withAverageRating() // ->whereHas('userReviews') // ->where('is_active', true) // ->whereNotNull('email_verified_at') // ->orderByDesc('user_reviews_avg_rating') // ->take($limit); // } public function categories() { return $this->belongsToMany(Category::class, 'category_user'); } public function destinations() { return $this->belongsToMany(Destination::class, 'destination_user'); } public function countries() { return $this->belongsToMany(Country::class, 'user_country'); } public function sentChats() { return $this->hasMany(UserChat::class, 'sender_id'); } public function receivedChats() { return $this->hasMany(UserChat::class, 'receiver_id'); } public function sendEmailVerificationNotification() { $this->notify((new \App\Notifications\QueuedVerifyEmail())->delay(now()->addSeconds(10))); } }
| ver. 1.4 |
Github
|
.
| PHP 8.1.29 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка