})->where('any', '(.*)\\/$'); // Route::get('products', array('as' => 'products', 'uses' => 'ProductsController@getIndex')); /* |-------------------------------------------------------------------------- | The API |-------------------------------------------------------------------------- | | | */ // Route::get('eventts/api', function(){ return Response::json(['eventts'=> json_decode(Eventt::all())]);}); // Route::get('test', function(){ return All::getSidelink(); }); // Route::get('api', function(){ return All::getRandomRecords(); }); // Route::get('api', function(){ return All::getLatestRecords(); }); Route::get('api', function () { return All::getAllRecords(); }); Route::post('api', function () { return All::getCoveredRecords(); }); Route::get('api/search', function () { return All::ajaxByLetters(); }); Route::get('{path}/api', function ($path) { return All::getModelRecords(); }); Route::get('{resource}/{id}/api', function ($resource, $id) { return All::getRecord($resource, $id); })->where('id', '[0-9]+'); Route::get('{resource}/{id}/edit/api', function ($resource, $id) { return All::getRecord($resource, $id);
public function getRecords() { $records = All::getAllRecords(); return $records; }
public static function ajaxByLetters() { $term = Input::get('term'); $api = All::getAllRecords(); // $api = substr($term, 1) ? $api : $this->getAllRecords();//query only once $coll = array(); foreach ($api as $key => $record) { foreach ($record as $key => $field) { if (count($coll) < 10) { if (stripos('x' . $field, $term)) { //stripos starts at char 1 not 0 $coll[$record['model_path'] . $record['id']] = array('model' => $record['model'], 'model_path' => $record['model_path'], 'name' => $record['name'], 'id' => $record['id'], 'location' => $record['location'], 'field' => $key); } } } } return Response::json($coll); }