|
|
@@ -38,80 +38,87 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
*/
|
|
|
class Provider extends Model
|
|
|
{
|
|
|
- use HasFactory, SoftDeletes;
|
|
|
+ use HasFactory, SoftDeletes;
|
|
|
|
|
|
- protected $table = "providers";
|
|
|
+ protected $table = "providers";
|
|
|
|
|
|
- protected $guarded = ["id"];
|
|
|
+ protected $guarded = ["id"];
|
|
|
|
|
|
- /**
|
|
|
- * Get the attributes that should be cast.
|
|
|
- *
|
|
|
- * @return array<string, string>
|
|
|
- */
|
|
|
- protected function casts(): array
|
|
|
- {
|
|
|
- return [
|
|
|
- "birth_date" => "date",
|
|
|
- "selfie_verified" => "boolean",
|
|
|
- "document_verified" => "boolean",
|
|
|
- "is_approved" => "boolean",
|
|
|
- "average_rating" => "decimal:1",
|
|
|
- "daily_price_8h" => "decimal:2",
|
|
|
- "daily_price_6h" => "decimal:2",
|
|
|
- "daily_price_4h" => "decimal:2",
|
|
|
- "daily_price_2h" => "decimal:2",
|
|
|
- "total_services" => "integer",
|
|
|
- ];
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @return BelongsTo
|
|
|
- */
|
|
|
- public function user(): BelongsTo
|
|
|
- {
|
|
|
- return $this->belongsTo(User::class, "user_id");
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * Get the attributes that should be cast.
|
|
|
+ *
|
|
|
+ * @return array<string, string>
|
|
|
+ */
|
|
|
+ protected function casts(): array
|
|
|
+ {
|
|
|
+ return [
|
|
|
+ "birth_date" => "date",
|
|
|
+ "selfie_verified" => "boolean",
|
|
|
+ "document_verified" => "boolean",
|
|
|
+ "is_approved" => "boolean",
|
|
|
+ "average_rating" => "decimal:1",
|
|
|
+ "daily_price_8h" => "decimal:2",
|
|
|
+ "daily_price_6h" => "decimal:2",
|
|
|
+ "daily_price_4h" => "decimal:2",
|
|
|
+ "daily_price_2h" => "decimal:2",
|
|
|
+ "total_services" => "integer",
|
|
|
+ ];
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * @return BelongsTo
|
|
|
- */
|
|
|
- public function profileMedia(): BelongsTo
|
|
|
- {
|
|
|
- return $this->belongsTo(Media::class, "profile_media_id");
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * @return BelongsTo
|
|
|
+ */
|
|
|
+ public function user(): BelongsTo
|
|
|
+ {
|
|
|
+ return $this->belongsTo(User::class, "user_id");
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
- */
|
|
|
- public function blockedClients()
|
|
|
- {
|
|
|
- return $this->hasMany(ProviderClientBlock::class);
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * @return BelongsTo
|
|
|
+ */
|
|
|
+ public function profileMedia(): BelongsTo
|
|
|
+ {
|
|
|
+ return $this->belongsTo(Media::class, "profile_media_id");
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
- */
|
|
|
- public function blockedByClients()
|
|
|
- {
|
|
|
- return $this->hasMany(ClientProviderBlock::class);
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
+ */
|
|
|
+ public function blockedClients()
|
|
|
+ {
|
|
|
+ return $this->hasMany(ProviderClientBlock::class);
|
|
|
+ }
|
|
|
|
|
|
- public function updateAverageRating(float $newRating): void
|
|
|
- {
|
|
|
- $totalReviews = Review::where('reviews.origin', 'client')
|
|
|
- ->leftJoin('schedules', 'schedules.id', '=', 'reviews.schedule_id')
|
|
|
- ->where('schedules.provider_id', $this->id)
|
|
|
- ->count();
|
|
|
+ /**
|
|
|
+ * @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
+ */
|
|
|
+ public function blockedByClients()
|
|
|
+ {
|
|
|
+ return $this->hasMany(ClientProviderBlock::class);
|
|
|
+ }
|
|
|
|
|
|
- if ($totalReviews === 0) {
|
|
|
- $this->average_rating = $newRating;
|
|
|
- } else {
|
|
|
- $currentTotalRating = $this->average_rating * ($totalReviews - 1);
|
|
|
- $newAverage = ($currentTotalRating + $newRating) / $totalReviews;
|
|
|
- $this->average_rating = round($newAverage, 2);
|
|
|
- }
|
|
|
+ public function updateAverageRating(float $newRating): void
|
|
|
+ {
|
|
|
+ $totalReviews = Review::where('reviews.origin', 'client')
|
|
|
+ ->leftJoin('schedules', 'schedules.id', '=', 'reviews.schedule_id')
|
|
|
+ ->where('schedules.provider_id', $this->id)
|
|
|
+ ->count();
|
|
|
|
|
|
- $this->save();
|
|
|
+ if ($totalReviews === 0) {
|
|
|
+ $this->average_rating = $newRating;
|
|
|
+ } else {
|
|
|
+ $currentTotalRating = $this->average_rating * ($totalReviews - 1);
|
|
|
+ $newAverage = ($currentTotalRating + $newRating) / $totalReviews;
|
|
|
+ $this->average_rating = round($newAverage, 2);
|
|
|
}
|
|
|
+
|
|
|
+ $this->save();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function primaryAddress()
|
|
|
+ {
|
|
|
+ return $this->hasOne(Address::class, "source_id")
|
|
|
+ ->where("source", "provider")
|
|
|
+ ->orderBy("is_primary", "desc");
|
|
|
+ }
|
|
|
}
|