Files
eatvio-infra/app/Models/User.php
2023-12-18 14:51:58 +03:00

229 lines
5.6 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;
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',
);
}
}