/
itp_practice
/
itp_backend
Обзор
Документация
Войти
/
itp_practice
/
itp_backend
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
master
app/Models/TapApp.php
145 строк
3 KB
vivanenko
fix taps and others structure
27 май 2025, 18:06
27 май 2025, 18:06
8cdc7d9
Код
Авторство
О чём код?
<?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; /** * @property int $id * @property string $name * @property string|null $description * @property bool $is_active * @property float $profitability * @property string $work_name * @property \DateTime|null $listing_date * @property float|null $profability * @property string|null $video_url * @property string|null $icon_url * @property \DateTime $created_at * @property \DateTime $updated_at * @property \DateTime|null $deleted_at */ class TapApp extends Model { use HasFactory, SoftDeletes; protected $fillable = [ 'name', 'description', 'is_active', 'profitability', 'work_name', 'listing_date', 'profability', 'video_url', 'icon_url', ]; protected $casts = [ 'is_active' => 'boolean', 'profitability' => 'decimal:2', 'profability' => 'decimal:2', 'listing_date' => 'datetime', ]; /** * Get the tariffs that include this tap app */ public function tariffs(): BelongsToMany { return $this->belongsToMany(Tariff::class, 'tariff_tap_apps') ->withTimestamps(); } /** * Get all taps for this app */ public function taps(): HasMany { return $this->hasMany(Tap::class); } /** * Get active taps for this app */ public function activeTaps(): HasMany { return $this->hasMany(Tap::class)->where('is_active', true); } /** * Scope to get only active tap apps */ public function scopeActive($query) { return $query->where('is_active', true); } /** * Get the name of the tap app */ public function getName(): string { return $this->name; } /** * Get the description of the tap app */ public function getDescription(): ?string { return $this->description; } /** * Get the work name (unique identifier) */ public function getWorkName(): string { return $this->work_name; } /** * Get the profitability */ public function getProfitability(): float { return (float) $this->profitability; } /** * Check if the tap app is active */ public function isActive(): bool { return $this->is_active; } /** * Get the icon URL with fallback */ public function getIconUrl(): ?string { return $this->icon_url; } /** * Get the video URL */ public function getVideoUrl(): ?string { return $this->video_url; } /** * Get the listing date */ public function getListingDate(): ?\DateTime { return $this->listing_date; } }