本文整理汇总了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.');
}