Skip to content

Instantly share code, notes, and snippets.

@thelinuxlich
Last active December 23, 2015 11:38
Show Gist options
  • Save thelinuxlich/6629372 to your computer and use it in GitHub Desktop.
Save thelinuxlich/6629372 to your computer and use it in GitHub Desktop.
<?php
class RoleController extends BaseController {
public function getIndex()
{
return Response::json(Role::all());
}
public function postCreate()
{
return $this->save(new Role);
}
public function getShow($id)
{
return Response::json(Role::find($id));
}
public function save($obj) {
try {
$obj->fill(Input::all())->save();
return Response::json(array("status" => true,"msg" => "Nível gravado com sucesso."));
} catch(Exception $e) {
return Response::json(array("status" => false,"msg" => "Ocorreu um erro ao tentar gravar o nível."));
}
}
public function postUpdate($id)
{
return $this->save(Role::find($id));
}
public function postDestroy($id)
{
try {
Role::destroy($id);
return Response::json(array("status" => true));
} catch(Exception $e) {
return Response::json(array("status" => false,"msg" => "Não foi possível remover o nível."));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment