Skip to content

Instantly share code, notes, and snippets.

@jaggy
Last active August 29, 2015 14:24
Show Gist options
  • Save jaggy/79e37b2e93a1eb899913 to your computer and use it in GitHub Desktop.
Save jaggy/79e37b2e93a1eb899913 to your computer and use it in GitHub Desktop.
<?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