本文整理匯總了PHP中app\Location::level方法的典型用法代碼示例。如果您正苦於以下問題:PHP Location::level方法的具體用法?PHP Location::level怎麽用?PHP Location::level使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\Location
的用法示例。
在下文中一共展示了Location::level方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getIndex
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function getIndex()
{
$per_page = Input::get('per_page', 100);
$page = Input::get('page', 1);
$level = Input::get('level', null);
$skip = ($page - 1) * $per_page;
// validate
$rules['per_page'] = ['numeric', 'between:1,100'];
$rules['page'] = ['numeric', 'min:1'];
$rules['level'] = ['in:continent,country,province,city,suburb'];
$validator = Validator::make(['per_page' => $per_page, 'page' => $page, 'level' => $level], $rules);
if ($validator->fails()) {
return response()->json(JSend::fail($validator->messages()->toArray()));
}
//
$locations = Location::level($level)->orderBy('path')->skip($skip)->take($per_page)->get();
if ($locations->count()) {
return response()->json(JSend::success($locations->toArray())->encode());
} else {
return response()->json(JSend::fail(['Data not found'])->encode());
}
}