Last active
August 29, 2015 14:24
-
-
Save jaggy/79e37b2e93a1eb899913 to your computer and use it in GitHub Desktop.
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 | |
/* | |
|-------------------------------------------------------------------------- | |
| Application Routes | |
|-------------------------------------------------------------------------- | |
| | |
| Here is where you can register all of the routes for an application. | |
| It's a breeze. Simply tell Laravel the URIs it should respond to | |
| and give it the controller to call when that URI is requested. | |
| | |
*/ | |
use Illuminate\Http\Request; | |
Route::get('/', function (Request $request) { | |
$page = $request->get('page'); | |
$limit = $request->get('limit'); | |
$conditions = $request->get('where') ?: []; | |
$OrConditions = $request->get('whereOr') ?: []; | |
$user = new User; | |
foreach ($conditions as $key => $value) { | |
$user = $user->where($key, $value); | |
} | |
if ($OrConditions) { | |
$user = $user->orWhere(function ($query) use ($OrConditions) { | |
foreach ($OrConditions as $key => $value) { | |
$query->where($key, $value); | |
} | |
}); | |
} | |
if ($limit) { | |
$user = $user->take($limit); | |
} | |
if ($page) { | |
$user = $user->skip($page); | |
} | |
return $user->get(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment