Created
February 12, 2017 21:05
-
-
Save evercode1/737134d8e6f28471bb132004ff4777d1 to your computer and use it in GitHub Desktop.
chapter 15 LessonQuery.php revised
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Queries\GridQueries; | |
| use DB; | |
| use App\Queries\GridQueries\Contracts\DataQuery; | |
| class LessonQuery implements DataQuery | |
| { | |
| public function data($column, $direction) | |
| { | |
| $rows = DB::table('lessons') | |
| ->select('lessons.id as Id', | |
| 'lessons.name as Name', | |
| 'categories.name as Category', | |
| 'subcategories.name as Subcategory', | |
| 'lessons.slug as Slug', | |
| DB::raw('DATE_FORMAT(lessons.created_at,"%m-%d-%Y") as Created')) | |
| ->leftJoin('categories', 'category_id', '=', 'categories.id') | |
| ->leftJoin('subcategories', 'subcategory_id', '=', 'subcategories.id') | |
| ->orderBy($column, $direction) | |
| ->paginate(10); | |
| return $rows; | |
| } | |
| public function filteredData($column, $direction, $keyword) | |
| { | |
| $rows = DB::table('lessons') | |
| ->select('lessons.id as Id', | |
| 'lessons.name as Name', | |
| 'categories.name as Category', | |
| 'subcategories.name as Subcategory', | |
| 'lessons.slug as Slug', | |
| DB::raw('DATE_FORMAT(lessons.created_at,"%m-%d-%Y") as Created')) | |
| ->leftJoin('categories', 'category_id', '=', 'categories.id') | |
| ->leftJoin('subcategories', 'subcategory_id', '=', 'subcategories.id') | |
| ->where('name', 'like', '%' . $keyword . '%') | |
| ->orderBy($column, $direction) | |
| ->paginate(10); | |
| return $rows; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment