Skip to content

Instantly share code, notes, and snippets.

@Anahkiasen
Last active December 17, 2015 12:59
Show Gist options
  • Save Anahkiasen/5613463 to your computer and use it in GitHub Desktop.
Save Anahkiasen/5613463 to your computer and use it in GitHub Desktop.
To API or not to API
<?php
//////////////////////////////////////////////////////////////////////
//////////////////////// METHODOLOGIE SEPARÉE ////////////////////////
//////////////////////////////////////////////////////////////////////
// app/controllers/UsersController --------------------------------- /
class UsersController
{
public function getUser($id)
{
$user = User::findOrFail($id);
return View::make('users.show')
->with('user', $user);
}
}
// app/controllers/Api/UsersController ----------------------------- /
namespace Api;
class UsersController
{
public function getUser($id)
{
$user = User::findOrFail($id);
return $user;
}
}
<?php
//////////////////////////////////////////////////////////////////////
//////////////////////// METHODOLOGIE UNIFIÉE ////////////////////////
//////////////////////////////////////////////////////////////////////
// app/controllers/UsersController --------------------------------- /
class UsersController
{
/**
* Instance of the Users API
*
* @var Api\UsersController
*/
protected $api;
public function __construct()
{
$this->api = new Api\UsersController;
}
public function getUser($id)
{
$user = $this->api->getUser($id);
return View::make('users.show')
->with('user', $user);
}
}
// app/controllers/Api/UsersController ----------------------------- /
namespace Api;
class UsersController
{
public function getUser($id)
{
$user = User::findOrFail($id);
return $user;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment