[WIP] Setup of skeleton
This commit is contained in:
66
app/Repositories/Cities.php
Normal file
66
app/Repositories/Cities.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Ville;
|
||||
|
||||
class Villes
|
||||
{
|
||||
public static function getVillesByName($query)
|
||||
{
|
||||
return Ville::select('id', DB::raw("concat(nom,' (',code_postal,')') as text"))->where('nom', 'LIKE', "$query%")->orderBy('nom', 'ASC')->take(30)->get();
|
||||
}
|
||||
|
||||
public static function getVillesByCP($query)
|
||||
{
|
||||
return Ville::select('id', DB::raw("concat(nom,' (',code_postal,')') as text"))->where('code_postal', 'LIKE', "%q$guery%")->orderBy('nom', 'ASC')->take(30)->get();
|
||||
}
|
||||
|
||||
public static function getCPByVille($id)
|
||||
{
|
||||
$ville = self::get($id);
|
||||
$codes = explode("-", $ville->code_postal);
|
||||
return $codes;
|
||||
}
|
||||
|
||||
public static function getNomByVille($id)
|
||||
{
|
||||
$ville = self::get($id);
|
||||
return $ville->nom;
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Ville::find($id);
|
||||
}
|
||||
|
||||
public static function getCoords($adresse)
|
||||
{
|
||||
// dd(app('geocoder')->geocode('Los Angeles, CA')->get());
|
||||
// dd(app('geocoder')->geocode('5 boulevard du Port, Amiens, France')->get());
|
||||
// dump($adresse);
|
||||
$geocode = app('geocoder')->geocode($adresse)->get();
|
||||
// dump($geocode);
|
||||
if (count($geocode)) {
|
||||
// dump($geocode);
|
||||
$res = $geocode[0]->getCoordinates()->toArray();
|
||||
// dump($res);
|
||||
$latitude = $res[0];
|
||||
$longitude = $res[1];
|
||||
// dump($latitude);
|
||||
// dump($longitude);
|
||||
return ['latitude' => $latitude, 'longitude' => $longitude];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function getCoordsByVille($id)
|
||||
{
|
||||
$ville = Ville::find($id);
|
||||
return ['latitude' => $ville->latitude, 'longitude' => $ville->longitude];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user