2023-04-03 10:47:55 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Fo;
|
|
|
|
|
|
2023-04-05 09:46:24 +00:00
|
|
|
use App\Http\Controllers\Controller;
|
2023-04-03 10:47:55 +00:00
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
|
|
class StoreController extends Controller
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Store by city
|
|
|
|
|
*
|
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
|
* @param mixed $city
|
|
|
|
|
* @return \App\Store;
|
|
|
|
|
*/
|
|
|
|
|
public function city(Request $request, mixed $city)
|
|
|
|
|
{
|
|
|
|
|
// CSRF Token check.
|
|
|
|
|
if (
|
|
|
|
|
!(is_string($request->session()->token()) &&
|
|
|
|
|
is_string($request->header('X-CSRF-TOKEN')) &&
|
|
|
|
|
hash_equals($request->session()->token(), $request->header('X-CSRF-TOKEN')))
|
|
|
|
|
) {
|
|
|
|
|
\abort(419);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (is_numeric($city)) {
|
|
|
|
|
$stores = DB::table('stores')
|
2023-04-05 09:46:24 +00:00
|
|
|
->join('store_regions', 'stores.region_id', '=', 'store_regions.id')
|
|
|
|
|
->join('store_groups', 'store_regions.group_id', '=', 'store_groups.id')
|
|
|
|
|
->select('stores.*', 'store_regions.*', 'store_groups.*')
|
2023-04-03 10:47:55 +00:00
|
|
|
->where('stores.zipcode', $city)
|
|
|
|
|
->get();
|
|
|
|
|
|
|
|
|
|
return $stores;
|
|
|
|
|
} else {
|
|
|
|
|
$stores = DB::table('stores')
|
2023-04-05 09:46:24 +00:00
|
|
|
->join('store_regions', 'stores.region_id', '=', 'store_regions.id')
|
|
|
|
|
->join('store_groups', 'store_regions.group_id', '=', 'store_groups.id')
|
|
|
|
|
->select('stores.*', 'store_regions.*', 'store_groups.*')
|
2023-04-03 10:47:55 +00:00
|
|
|
->where('stores.city', $city)
|
|
|
|
|
->get();
|
|
|
|
|
|
|
|
|
|
return $stores;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|