aboutsummaryrefslogtreecommitdiff
path: root/src/controllers
diff options
context:
space:
mode:
authorCamil Staps2015-04-26 16:51:55 +0200
committerCamil Staps2015-04-26 16:51:55 +0200
commit8da7a4e77a1a353b83d1f22a745a6a7ef9e24398 (patch)
tree577d8354c8b3952be2687cd650565c6bec656be3 /src/controllers
parentOnly HTTPS allowed (diff)
user.create endpoint
Diffstat (limited to 'src/controllers')
-rw-r--r--src/controllers/UserController.php29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/controllers/UserController.php b/src/controllers/UserController.php
index 39c2be6..33e945d 100644
--- a/src/controllers/UserController.php
+++ b/src/controllers/UserController.php
@@ -1,18 +1,43 @@
<?php
namespace CamilStaps\BotleaguesApi;
+use Illuminate\Support\Facades\Hash;
+use Illuminate\Support\Facades\Input;
+use Illuminate\Support\Facades\Redirect;
+
class UserController extends BaseController {
+ protected $user;
+
+ public function __construct(User $user) {
+ $this->user = $user;
+ }
+
public function index() {
- return User::all();
+ return $this->user->all();
}
public function show($id) {
- return User::findOrFail($id);
+ return $this->user->findOrFail($id);
}
public function edit($id) {
return $this->response->noContent();
}
+ public function store() {
+ try {
+ $this->user->email = Input::get('email');
+ $this->user->password = Hash::make(Input::get('password'));
+
+ if ($this->user->save()) {
+ return $this->response->created();
+ } else {
+ throw new Dingo\Api\Exception\StoreResourceFailedException;
+ }
+ } catch (Exception $e) {
+ throw new Dingo\Api\Exception\StoreResourceFailedException;
+ }
+ }
+
} \ No newline at end of file