%PDF- %PDF-
Direktori : /www/loslex/demo/app/Models/ |
Current File : //www/loslex/demo/app/Models/Range.php |
<?php namespace App\Models; use Carbon\Carbon; use App\Models\Contest; use Illuminate\Database\Eloquent\Model; use ASanikovich\LaravelSpatial\Geometry\Point; use Illuminate\Database\Eloquent\Casts\Attribute; use ASanikovich\LaravelSpatial\Eloquent\HasSpatial; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Factories\HasFactory; class Range extends Model { use HasSpatial; protected $fillable = [ 'name', 'address', 'note', 'web', 'email', 'phone', 'region' ]; protected $casts = [ 'coords' => Point::class ]; /* Contests for given contest */ /* @return \Illuminate\Database\Eloquent\Relations\HasMany */ public function registrations() : HasMany { return $this->hasMany(Contest::class); } public function getWazeLink(): Attribute { return Attribute::make( get: fn () => "https://www.waze.com/ul?ll={$this->coords->latitude}%2C{$this->coords->longitude}&navigate=yes&zoom=17" ); } public function location(): Attribute { return Attribute::make( get: fn () => $this->coords ? "{$this->coords->latitude}, {$this->coords->longitude}" : null, ); } public function contestcount(): Attribute { return Attribute::make( get: fn() => Contest::where('range_id', $this->id) ->where('published', 1) ->where('date', '>', Carbon::today()) ->count(), ); } public function setCoords(?string $value) { if (!is_null($value)) { $split = explode(", ", $value); $this->coords = new Point($split[0], $split[1]); } else { $this->coords = null; } } }