Skip to content

Commit e58110a

Browse files
committed
user registration API
1 parent 3a641df commit e58110a

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-1
lines changed

app/Exceptions/Handler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function report(Throwable $exception)
4949
* @throws \Throwable
5050
*/
5151
public function render($request, Throwable $exception)
52-
{
52+
{;
5353
return parent::render($request, $exception);
5454
}
5555
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use App\Http\Requests\RegistrationRequest;
6+
use App\User;
7+
8+
class RegistrationController extends Controller
9+
{
10+
public function register(RegistrationRequest $request) {
11+
User::create($request->getAttributes());
12+
13+
return $this->respondWithMessage('User successfully created');
14+
}
15+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace App\Http\Requests;
4+
5+
use Illuminate\Foundation\Http\FormRequest;
6+
use Hash;
7+
8+
class RegistrationRequest extends FormRequest
9+
{
10+
/**
11+
* Determine if the user is authorized to make this request.
12+
*
13+
* @return bool
14+
*/
15+
public function authorize()
16+
{
17+
return true;
18+
}
19+
20+
/**
21+
* Get the validation rules that apply to the request.
22+
*
23+
* @return array
24+
*/
25+
public function rules()
26+
{
27+
return [
28+
'name' => 'required|string',
29+
'email' => 'required|email',
30+
'password' => 'required|string|min:8|max:25',
31+
];
32+
}
33+
34+
public function getAttributes() {
35+
return array_merge(
36+
$this->only(['name', 'email']),
37+
['password' => Hash::make($this->get('password'))]
38+
);
39+
}
40+
}

routes/api.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@
2323
Route::post('logout', 'AuthController@logout');
2424
Route::post('refresh', 'AuthController@refresh');
2525
Route::get('me', 'AuthController@me');
26+
27+
Route::post('register', 'RegistrationController@register');
2628
});

0 commit comments

Comments
 (0)
close