Created
October 6, 2014 20:38
-
-
Save hskrasek/4892143acb79e4c0b3d0 to your computer and use it in GitHub Desktop.
REST Route Ideas
This file contains 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 | |
class AppointmentController extends \BaseController { | |
public function index($id) | |
{ | |
if ($id) { | |
$appts = $this->appointments->getAllForUser($id); | |
} else { | |
$appts = $this->appointments->getAll(); | |
} | |
return $appts; | |
} | |
} |
This file contains 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 | |
// 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