本文整理汇总了PHP中app\Student::orderBy方法的典型用法代码示例。如果您正苦于以下问题:PHP Student::orderBy方法的具体用法?PHP Student::orderBy怎么用?PHP Student::orderBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Student
的用法示例。
在下文中一共展示了Student::orderBy方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createQuery
/**
* @param StudentSearch $request
* @return mixed
*/
private function createQuery(StudentSearch $request)
{
if (!$this->search->createQuery($request->all())) {
return Student::orderBy('last_name', 'ASC')->paginate(10);
}
return $this->search->createQuery($request->all())->paginate(10);
}
示例2: createQuery
public function createQuery($request)
{
$first_name = $request['first_name'];
$last_name = $request['last_name'];
$year = $request['year'];
$section = $request['section'];
$city = $request['city'];
$age = $request['age'];
$zip = $request['zip'];
if ($zip || $first_name || $last_name || $year || $section || $city || array_key_exists($age, config('student.brackets'))) {
$q = Student::orderBy('last_name', 'ASC');
if ($first_name) {
$q = $q->where('first_name', 'like', "%{$first_name}");
}
if ($last_name) {
$q = $q->where('last_name', 'like', "%{$last_name}");
}
if ($zip) {
$q = $q->where('zip', $zip);
}
if ($year) {
$q = $q->where('year_level', $year);
}
if ($section) {
$q = $q->where('section_id', $section);
}
if ($city) {
$q = $q->where('city', $city);
}
if (array_key_exists($age, config('student.brackets'))) {
$age = explode('-', $age);
$q = $q->whereBetween('birthday', [Carbon::now()->subYears($age[1])->format('Y-m-d'), Carbon::now()->subYears($age[0])->format('Y-m-d')]);
}
return $q;
}
return false;
}
示例3: index
public function index()
{
return view('student.index', ['students' => Student::orderBy('name')->get()]);
}
示例4: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$student = Student::find(Crypt::decrypt($id));
if (count($student) == 0) {
return response()->json(['success' => false, 'message' => 'Invalid id!']);
}
if (!$student->delete()) {
return response()->json(['success' => false, 'message' => 'Failed to delete record!']);
}
$students = Student::orderBy('name')->get();
return response()->json(['success' => true, 'message' => 'Delete record successful!', 'content' => view('partials.student-table', compact('students'))->render()]);
}
示例5: export
public function export(Request $request)
{
if ($request->get('dob') && $request->get('from') && $request->get('to')) {
if ($request->get('from') < $request->get('to')) {
return response()->json(['success' => false, 'message' => 'From date must be lower than TO date']);
}
$dt = Carbon::now();
$dt2 = Carbon::now();
$from = $dt->subYears($request->get('from'));
$to = $dt2->subYears($request->get('to'));
$students = Student::where('dob', '<=', $from)->where('dob', '>=', $to)->orderBy('fname')->get();
} else {
$students = Student::orderBy('fname')->get();
}
header('Set-Cookie: fileDownload=true; path=/');
// This is required for the javascript triggering this will know if the transaction was successful.
$data = $this->generateReportData($students, $request);
Excel::create('reports-' . date('Ymd'), function ($excel) use($data) {
$excel->sheet("Student Data", function ($sheet) use($data) {
$sheet->fromArray($data);
});
})->download('xls');
}