%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/html/shaban/duassis/api/app/Models/
Upload File :
Create Path :
Current File : //var/www/html/shaban/duassis/api/app/Models/Address.php

<?php

namespace App\Models;

/**
 * @property integer id
 * @property integer country_id
 * @property string city
 * @property string street
 * @property float latitude
 * @property float longitude
 * @property Country country
 *
 */
class Address extends BaseModel
{
    protected $fillable = [
        'city',
        'street',
        'latitude',
        'longitude',
    ];

    protected $guarded = [
        'country_id',
    ];

    protected $casts = [
        'id'        => 'integer',
        'city'      => 'string',
        'street'    => 'string',
        'latitude'  => 'float',
        'longitude' => 'float',
    ];

    public function scopeIsWithinMaxDistance($query, $coordinates, $radius = 5)
    {
        $haversine = "(6371 * acos(cos(radians(" . $coordinates['latitude'] . "))
                    * cos(radians(`latitude`))
                    * cos(radians(`longitude`)
                    - radians(" . $coordinates['longitude'] . "))
                    + sin(radians(" . $coordinates['latitude'] . "))
                    * sin(radians(`latitude`))))";

        return $query->selectRaw("{$haversine} AS distance")
                     ->whereRaw("{$haversine} < ?", [$radius]);
    }

    public function country()
    {
        return $this->belongsTo(Country::class);
    }
}

Zerion Mini Shell 1.0