Files
eatvio-infra/app/Models/User.php
2023-12-29 11:44:24 +03:00

325 lines
12 KiB
PHP

<?php
namespace App\Models;
use CyrildeWit\EloquentViewable\Contracts\Viewable;
use CyrildeWit\EloquentViewable\InteractsWithViews;
use Illuminate\Auth\MustVerifyEmail as UserMustVerifyEmail;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Fortify\TwoFactorAuthenticatable;
use Laravel\Jetstream\HasProfilePhoto;
use Laravel\Sanctum\HasApiTokens;
/**
* App\Models\User
*
* @property int $id
* @property string $name
* @property string $email
* @property \Illuminate\Support\Carbon|null $email_verified_at
* @property string $password
* @property string|null $two_factor_secret
* @property string|null $two_factor_recovery_codes
* @property string|null $two_factor_confirmed_at
* @property string|null $remember_token
* @property int|null $current_team_id
* @property string|null $profile_photo_path
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property int $is_consultant
* @property int $is_public_profile 0 only friends, 1 all
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\UserAttachment> $attachments
* @property-read int|null $attachments_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\BlogPost> $author_of_blog_post
* @property-read int|null $author_of_blog_post_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Diet> $author_of_diets
* @property-read int|null $author_of_diets_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Plan> $author_of_plans
* @property-read int|null $author_of_plans_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Recipe> $author_of_recipe
* @property-read int|null $author_of_recipe_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\BlogPostCommentUpvote> $blog_post_comment_upvotes
* @property-read int|null $blog_post_comment_upvotes_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\BlogPostComment> $blog_post_comments
* @property-read int|null $blog_post_comments_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\BlogPostLike> $blog_post_likes
* @property-read int|null $blog_post_likes_count
* @property-read \App\Models\ChosenDiet|null $chosen_diet
* @property-read \App\Models\ChosenPlan|null $chosen_plan
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\CircumferenceMeasure> $circumference_measures
* @property-read int|null $circumference_measures_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\CommentUpvote> $comment_upvotes
* @property-read int|null $comment_upvotes_count
* @property-read \App\Models\ConsultantLegalEntity|null $consultant_legal_entity
* @property-read \App\Models\ConsultantEducation|null $consultant_request
* @property-read \App\Models\UserDetailz|null $detailz
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Diary> $diaries
* @property-read int|null $diaries_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\DietCommentUpvote> $diet_comment_upvotes
* @property-read int|null $diet_comment_upvotes_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\DietComment> $diet_comments
* @property-read int|null $diet_comments_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\DietLike> $diet_likes
* @property-read int|null $diet_likes_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Meal> $meals
* @property-read int|null $meals_count
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection<int, \Illuminate\Notifications\DatabaseNotification> $notifications
* @property-read int|null $notifications_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\PlanComment> $plan_comments
* @property-read int|null $plan_comments_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\PlanLike> $plan_likes
* @property-read int|null $plan_likes_count
* @property-read string $profile_photo_url
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\RecipeCommentUpvote> $recipe_comment_upvotes
* @property-read int|null $recipe_comment_upvotes_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\RecipeComment> $recipe_comments
* @property-read int|null $recipe_comments_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\RecipeLike> $recipe_likes
* @property-read int|null $recipe_likes_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \Laravel\Sanctum\PersonalAccessToken> $tokens
* @property-read int|null $tokens_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \CyrildeWit\EloquentViewable\View> $views
* @property-read int|null $views_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\WeightMeasure> $weight_measures
* @property-read int|null $weight_measures_count
* @method static \Database\Factories\UserFactory factory($count = null, $state = [])
* @method static \Illuminate\Database\Eloquent\Builder|User newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|User newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|User orderByUniqueViews(string $direction = 'desc', $period = null, ?string $collection = null, string $as = 'unique_views_count')
* @method static \Illuminate\Database\Eloquent\Builder|User orderByViews(string $direction = 'desc', ?\CyrildeWit\EloquentViewable\Support\Period $period = null, ?string $collection = null, bool $unique = false, string $as = 'views_count')
* @method static \Illuminate\Database\Eloquent\Builder|User query()
* @method static \Illuminate\Database\Eloquent\Builder|User whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereCurrentTeamId($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereEmail($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereEmailVerifiedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereIsConsultant($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereIsPublicProfile($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereName($value)
* @method static \Illuminate\Database\Eloquent\Builder|User wherePassword($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereProfilePhotoPath($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereRememberToken($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereTwoFactorConfirmedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereTwoFactorRecoveryCodes($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereTwoFactorSecret($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|User withViewsCount(?\CyrildeWit\EloquentViewable\Support\Period $period = null, ?string $collection = null, bool $unique = false, string $as = 'views_count')
* @mixin \Eloquent
*/
class User extends Authenticatable implements MustVerifyEmail, Viewable
{
use HasApiTokens;
use HasFactory;
use HasProfilePhoto;
use InteractsWithViews;
use Notifiable;
use TwoFactorAuthenticatable;
use UserMustVerifyEmail;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'password',
'is_public_profile',
];
/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
'two_factor_recovery_codes',
'two_factor_secret',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
/**
* The accessors to append to the model's array form.
*
* @var array<int, string>
*/
protected $appends = [
'profile_photo_url',
];
/* public function author_of_blog_post()
{
return $this->belongsToMany(BlogPost::class, 'blog_post_author');
}
public function author_of_plans()
{
return $this->belongsToMany(Plan::class, 'plan_author');
}
public function author_of_diets()
{
return $this->belongsToMany(Diet::class, 'diet_author');
}
public function author_of_recipe()
{
return $this->belongsToMany(Recipe::class, 'recipe_author');
}
*/
public function diaries(): HasMany
{
return $this->hasMany(Diary::class);
}
public function meals(): HasMany
{
return $this->hasMany(Meal::class);
}
public function detailz(): HasOne
{
return $this->hasOne(UserDetailz::class);
}
public function circumference_measures(): HasMany
{
return $this->hasMany(CircumferenceMeasure::class);
}
public function weight_measures(): HasMany
{
return $this->hasMany(WeightMeasure::class);
}
public function consultant_request(): HasOne
{
return $this->hasOne(ConsultantEducation::class);
}
public function attachments(): HasMany
{
return $this->hasMany(UserAttachment::class);
}
public function author_of_plans(): BelongsToMany
{
return $this->belongsToMany(Plan::class, 'plan_author', 'user_id', 'plan_id');
}
public function author_of_diets(): BelongsToMany
{
return $this->belongsToMany(Diet::class, 'diet_author', 'user_id', 'diet_id');
}
public function author_of_blog_post(): BelongsToMany
{
return $this->belongsToMany(BlogPost::class, 'blog_post_author', 'user_id', 'blog_post_id');
}
public function author_of_recipe(): BelongsToMany
{
return $this->belongsToMany(Recipe::class, 'recipe_author', 'user_id', 'recipe_id');
}
public function plan_comments(): HasMany
{
return $this->hasMany(PlanComment::class);
}
public function plan_likes(): HasMany
{
return $this->hasMany(PlanLike::class);
}
public function diet_comments(): HasMany
{
return $this->hasMany(DietComment::class);
}
public function diet_likes(): HasMany
{
return $this->hasMany(DietLike::class);
}
public function comment_upvotes(): HasMany
{
return $this->hasMany(CommentUpvote::class);
}
public function diet_comment_upvotes(): HasMany
{
return $this->hasMany(DietCommentUpvote::class);
}
public function chosen_plan(): HasOne
{
return $this->hasOne(ChosenPlan::class);
}
public function chosen_diet(): HasOne
{
return $this->hasOne(ChosenDiet::class);
}
public function blog_post_comments(): HasMany
{
return $this->hasMany(BlogPostComment::class);
}
public function blog_post_likes(): HasMany
{
return $this->hasMany(BlogPostLike::class);
}
public function blog_post_comment_upvotes(): HasMany
{
return $this->hasMany(BlogPostCommentUpvote::class);
}
public function recipe_comments(): HasMany
{
return $this->hasMany(RecipeComment::class);
}
public function recipe_likes(): HasMany
{
return $this->hasMany(RecipeLike::class);
}
public function recipe_comment_upvotes(): HasMany
{
return $this->hasMany(RecipeCommentUpvote::class);
}
public function consultant_legal_entity(): HasOne
{
return $this->hasOne(ConsultantLegalEntity::class);
}
protected function consultantState(): Attribute
{
return Attribute::make(
get: fn () => $this->consultant_request ? $this->consultant_request->request_state : 'incomplete',
);
}
}