本文整理匯總了PHP中app\Location::isState方法的典型用法代碼示例。如果您正苦於以下問題:PHP Location::isState方法的具體用法?PHP Location::isState怎麽用?PHP Location::isState使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\Location
的用法示例。
在下文中一共展示了Location::isState方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: query
/**
* General string query (not zip or lat/lng) - could be address, city, state, or name
* @param string $query text input from homepage
* @return json
*/
public function query($query)
{
$res = new \stdClass();
//check if query is a state
$state = Location::isState($query);
if (null !== $state) {
$res->reps = Representative::state($state)->get()->all();
$res->location = (object) ['state' => $state, 'state_name' => Location::states[$state]];
$res->reps[] = Representative::where('office', 'President')->first();
usort($res->reps, 'rankSort');
return response()->json($res);
}
//if query has number try address
if (preg_match('/[0-9,]/', $query)) {
$address = $this->address($query);
if (isset($address->getData()->status) && $address->getData()->status == "error") {
return $this->error($address->getData()->message);
}
if (count($address->getData()->reps) > 0) {
return $address;
}
}
//if query doesnt have number try name
$reps = Representative::name($query)->orderBy('name')->get()->all();
if (count($reps) > 0) {
$res->reps = $reps;
return response()->json($res);
}
//if no name, or state, try address
$address = $this->address($query);
if (isset($address->getData()->reps) && count($address->getData()->reps) > 0) {
return $address;
}
return $this->error('No results.');
}