. */ declare(strict_types=1); namespace FireflyIII\Models; use Eloquent; use FireflyIII\User; use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\MorphMany; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Query\Builder; use Illuminate\Support\Carbon; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** * FireflyIII\Models\Tag * * @property int $id * @property Carbon|null $created_at * @property Carbon|null $updated_at * @property Carbon|null $deleted_at * @property int $user_id * @property string $tag * @property string $tagMode * @property Carbon|null $date * @property string|null $description * @property float|null $latitude * @property float|null $longitude * @property int|null $zoomLevel * @property-read Collection|Attachment[] $attachments * @property-read int|null $attachments_count * @property-read Collection|Location[] $locations * @property-read int|null $locations_count * @property-read Collection|TransactionJournal[] $transactionJournals * @property-read int|null $transaction_journals_count * @property-read User $user * @method static \Illuminate\Database\Eloquent\Builder|Tag newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Tag newQuery() * @method static Builder|Tag onlyTrashed() * @method static \Illuminate\Database\Eloquent\Builder|Tag query() * @method static \Illuminate\Database\Eloquent\Builder|Tag whereCreatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|Tag whereDate($value) * @method static \Illuminate\Database\Eloquent\Builder|Tag whereDeletedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|Tag whereDescription($value) * @method static \Illuminate\Database\Eloquent\Builder|Tag whereId($value) * @method static \Illuminate\Database\Eloquent\Builder|Tag whereLatitude($value) * @method static \Illuminate\Database\Eloquent\Builder|Tag whereLongitude($value) * @method static \Illuminate\Database\Eloquent\Builder|Tag whereTag($value) * @method static \Illuminate\Database\Eloquent\Builder|Tag whereTagMode($value) * @method static \Illuminate\Database\Eloquent\Builder|Tag whereUpdatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|Tag whereUserId($value) * @method static \Illuminate\Database\Eloquent\Builder|Tag whereZoomLevel($value) * @method static Builder|Tag withTrashed() * @method static Builder|Tag withoutTrashed() * @mixin Eloquent * @property int|null $user_group_id * @method static \Illuminate\Database\Eloquent\Builder|Tag whereUserGroupId($value) */ class Tag extends Model { use SoftDeletes; /** * The attributes that should be casted to native types. * * @var array */ protected $casts = [ 'created_at' => 'datetime', 'updated_at' => 'datetime', 'deleted_at' => 'datetime', 'date' => 'date', 'zoomLevel' => 'int', 'latitude' => 'float', 'longitude' => 'float', ]; /** @var array Fields that can be filled */ protected $fillable = ['user_id', 'tag', 'date', 'description', 'tagMode']; protected $hidden = ['zoomLevel', 'latitude', 'longitude']; /** * Route binder. Converts the key in the URL to the specified object (or throw 404). * * @param string $value * * @return Tag * @throws NotFoundHttpException */ public static function routeBinder(string $value): Tag { if (auth()->check()) { $tagId = (int) $value; /** @var User $user */ $user = auth()->user(); /** @var Tag $tag */ $tag = $user->tags()->find($tagId); if (null !== $tag) { return $tag; } } throw new NotFoundHttpException(); } /** * @codeCoverageIgnore * @return MorphMany */ public function attachments(): MorphMany { return $this->morphMany(Attachment::class, 'attachable'); } /** * @codeCoverageIgnore * @return MorphMany */ public function locations(): MorphMany { return $this->morphMany(Location::class, 'locatable'); } /** * @codeCoverageIgnore * @return BelongsToMany */ public function transactionJournals(): BelongsToMany { return $this->belongsToMany(TransactionJournal::class); } /** * @codeCoverageIgnore * @return BelongsTo */ public function user(): BelongsTo { return $this->belongsTo(User::class); } }