Refactoring, change menu, add many features
This commit is contained in:
@@ -5,28 +5,28 @@ namespace App\Repositories;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Ville;
|
||||
use App\Models\City;
|
||||
|
||||
class Villes
|
||||
class Cities
|
||||
{
|
||||
public static function getVillesByName($query)
|
||||
public static function getCitiesByName($query)
|
||||
{
|
||||
return Ville::select('id', DB::raw("concat(nom,' (',code_postal,')') as text"))->where('nom', 'LIKE', "$query%")->orderBy('nom', 'ASC')->take(30)->get();
|
||||
return City::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)
|
||||
public static function getCitiesByCP($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();
|
||||
return City::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)
|
||||
public static function getCPByCity($id)
|
||||
{
|
||||
$ville = self::get($id);
|
||||
$codes = explode("-", $ville->code_postal);
|
||||
return $codes;
|
||||
}
|
||||
|
||||
public static function getNomByVille($id)
|
||||
public static function getNomByCity($id)
|
||||
{
|
||||
$ville = self::get($id);
|
||||
return $ville->nom;
|
||||
@@ -34,7 +34,7 @@ class Villes
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Ville::find($id);
|
||||
return City::find($id);
|
||||
}
|
||||
|
||||
public static function getCoords($adresse)
|
||||
@@ -58,9 +58,9 @@ class Villes
|
||||
}
|
||||
}
|
||||
|
||||
public static function getCoordsByVille($id)
|
||||
public static function getCoordsByCity($id)
|
||||
{
|
||||
$ville = Ville::find($id);
|
||||
$ville = City::find($id);
|
||||
return ['latitude' => $ville->latitude, 'longitude' => $ville->longitude];
|
||||
}
|
||||
}
|
||||
|
||||
54
app/Repositories/Shop/Deliveries.php
Normal file
54
app/Repositories/Shop/Deliveries.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Delivery;
|
||||
|
||||
class Deliveries
|
||||
{
|
||||
public static function getOptions()
|
||||
{
|
||||
return Delivery::orderBy('name', 'asc')->get()->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Delivery::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Delivery::find($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = $data['id'] ?? false;
|
||||
$item = $id ? self::update($data, $id) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return Delivery::create($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = $id ? $id : $data['id'];
|
||||
$delivery = self::get($id);
|
||||
$delivery->update($data);
|
||||
return $delivery;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Delivery::destroy($id);
|
||||
}
|
||||
|
||||
public static function toggle_active($id, $active)
|
||||
{
|
||||
return self::update(['active' => $active], $id);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user