예제 #1
0
 public function getQuiz($id)
 {
     $quizzes = Quiz::where('quiz_id', (int) $id)->with('user')->with('questions')->with('results')->with('media')->get();
     $api = new ApiHandler();
     $api->enableSideloading();
     if ($quizzes->count() > 0) {
         $api->setCollection($quizzes);
     } else {
         $api->setState(404, 'not_found');
     }
     return $api->send();
 }
예제 #2
0
use App\Library\Api\Handler as ApiHandler;
/*
|--------------------------------------------------------------------------
| 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.
|
*/
header("Access-Control-Allow-Origin: *");
header('Access-Control-Allow-Credentials: true');
Route::get('/', function () {
    $api = new ApiHandler('V1');
    $api->addLink('quizzes', route('get_quizzes'));
    return $api->send();
});
//************************************************************* Quizzes
Route::get('/quizzes', ['as' => 'get_quizzes', 'uses' => 'QuizzesController@getQuizzes']);
# get home
Route::get('/quizzes/{id}', ['as' => 'get_quiz', 'uses' => 'QuizzesController@getQuiz']);
# get one
Route::post('/quizzes/{id}', ['as' => 'post_quiz_response', 'uses' => 'QuizzesController@postQuiz']);
# send response
Route::get('/quizzes/{id}/likes', ['as' => 'get_quiz_likes', 'uses' => 'LikesController@getQuizLikes']);
# get comments
// Route::get('/quizzes/{id}/likes/'); # get all likes for a quizz
// Route::post('/quizzes/{id}/likes/'); # like a quizz
// Route::delete('/quizzes/{id}/likes/'); # unlike a quizz