60 lines
1.6 KiB
PHP
60 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
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();
|
|
}
|
|
|
|
}
|
|
}
|