ldc-wenn-dann-mit-respekt/app/Http/Controllers/StoreController.php
Vincent BRIDIER 9cd503affd
PHPCBF
2022-11-18 15:35:39 +01:00

59 lines
1.5 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Store;
use Illuminate\Support\Facades\DB;
class StoreController extends Controller
{
// Stores
public function index()
{
return Store::all();
}
public function show($id)
{
return Store::find($id);
}
// Stores by city
public function city($city)
{
if (is_numeric($city)) {
return Store::where('zipcode', '=', $city)->get();
} else {
return Store::where('city', '=', $city)->get();
}
}
// Stores by city
public function city2($city)
{
if (is_numeric($city)) {
// return Store::where('zipcode', '=', $city)->get();
$stores = DB::table('stores')
->join('retailregions', 'stores.region_id', '=', 'retailregions.id')
->join('retailgroups', 'retailregions.region_group', '=', 'retailgroups.id')
->select('stores.*', 'retailregions.*', 'retailgroups.*')
->where('stores.zipcode', $city)
->get();
return $stores;
} else {
$stores = DB::table('stores')
->join('retailregions', 'stores.region_id', '=', 'retailregions.id')
->join('retailgroups', 'retailregions.region_group', '=', 'retailgroups.id')
->select('stores.*', 'retailregions.*', 'retailgroups.*')
->where('stores.city', $city)
->get();
return $stores;
// return Store::where('city', '=', $city)->get();
}//end if
}
}