Skip to content

Instantly share code, notes, and snippets.

@hskrasek
Created October 6, 2014 20:38
Show Gist options
  • Save hskrasek/4892143acb79e4c0b3d0 to your computer and use it in GitHub Desktop.
Save hskrasek/4892143acb79e4c0b3d0 to your computer and use it in GitHub Desktop.
REST Route Ideas
<?php
class AppointmentController extends \BaseController {
public function index($id)
{
if ($id) {
$appts = $this->appointments->getAllForUser($id);
} else {
$appts = $this->appointments->getAll();
}
return $appts;
}
}
<?php
// Basic CRUD endpoints from this
Route::resource('users', 'UserController');
// Then you have two options for /users/{id}/appointments, this:
Route::get('users/{id}/appointments', 'UserController@appointments');
// Or this:
Route::get('users/{id}/appointments', 'AppointmentController@index');
// The second one might be more desirable, since you already
// have the assets to get appointments in that controller, and Laravel will
// Reveal that you have an ID being passed to the function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment