stilldesign/distance-scope-trait

Laravel 模型的距离范围特性

dev-master 2017-09-14 13:08 UTC

This package is not auto-updated.

Last update: 2024-09-29 05:07:53 UTC


README

为 Laravel 模型添加距离范围特性

安装

"stilldesign/distance-scope-trait": "dev-master"

使用

在模型中

<?php

namespace App\Models;

use Stilldesign\DistanceScopeTrait\DistanceScopeTrait;

class ExampleModel extends Model
{

use DistanceScopeTrait;

...
}

在控制器中

<?php

use App\Models\ExampleModel;

class ExampleController extends Model
{

    public function index
    (
        ...
        $exampleModelItems = ExampleModel::distance($lattitude, $longitue, 100)->get();
        // all items in the given coordinates, within 100 kilometers
        ...
    )

...
}