Created
February 11, 2017 19:16
-
-
Save evercode1/246f9b90b73e2e42acfed1eb662a3ca4 to your computer and use it in GitHub Desktop.
chapter 15 SubcategoryQuery.php
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 SubcategoryQuery implements DataQuery | |
| { | |
| public function data($column, $direction) | |
| { | |
| $rows = DB::table('subcategories') | |
| ->select('subcategories.id as Id', | |
| 'subcategories.name as Name', | |
| 'categories.name as Category', | |
| 'categories.id as CategoryId', | |
| DB::raw('DATE_FORMAT(subcategories.created_at, | |
| "%m-%d-%Y") as Created')) | |
| ->leftJoin('categories', 'category_id', '=', 'categories.id') | |
| ->orderBy($column, $direction) | |
| ->paginate(10); | |
| return $rows; | |
| } | |
| public function filteredData($column, $direction, $keyword) | |
| { | |
| $rows = DB::table('subcategories') | |
| ->select('subcategories.id as Id', | |
| 'subcategories.name as Name', | |
| 'categories.name as Category', | |
| 'categories.id as CategoryId', | |
| DB::raw('DATE_FORMAT(subcategories.created_at, | |
| "%m-%d-%Y") as Created')) | |
| ->leftJoin('categories', 'category_id', '=', 'categories.id') | |
| ->where('subcategories.name', 'like', '%' . $keyword . '%') | |
| ->orWhere('categories.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