Skip to content

Commit 1540437

Browse files
authored
Register (#5)
* Create RegisterController.php * Add register routes * Add Register Vue page component * Add tests for RegisterController * Add links between Login and Register pages
1 parent eb596cb commit 1540437

File tree

12 files changed

+539
-179
lines changed

12 files changed

+539
-179
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use App\Http\Controllers\Controller;
6+
use App\Http\Requests\Register\RegisterStore;
7+
use App\Models\User;
8+
use Illuminate\Support\Facades\App;
9+
use Illuminate\Support\Facades\Auth;
10+
use Illuminate\Support\Facades\Redirect;
11+
use Inertia\Inertia;
12+
13+
class RegisterController extends Controller
14+
{
15+
public function show()
16+
{
17+
$isProd = App::environment('production');
18+
19+
return Inertia::render('Register', [
20+
'first_name' => !$isProd ? 'Jim' : '',
21+
'last_name' => !$isProd ? 'Gordon' : '',
22+
'email' => !$isProd ? 'test@test.com' : '',
23+
'password' => !$isProd ? '123456Ab#' : '',
24+
]);
25+
}
26+
27+
public function store(RegisterStore $request)
28+
{
29+
$user = new User($request->only('first_name', 'last_name', 'email'));
30+
31+
$user->password = $request->validated('password');
32+
$user->save();
33+
34+
Auth::loginUsingId($user->id);
35+
36+
return Redirect::route('home');
37+
}
38+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace App\Http\Requests\Register;
4+
5+
use Illuminate\Foundation\Http\FormRequest;
6+
use Illuminate\Validation\Rules\Password;
7+
8+
class RegisterStore extends FormRequest
9+
{
10+
public function rules()
11+
{
12+
return [
13+
'first_name' => ['required', 'string'],
14+
'last_name' => ['required', 'string'],
15+
'email' => ['required', 'email', 'unique:users'],
16+
'password' => [
17+
'required',
18+
Password::min(6)
19+
->mixedCase()
20+
->numbers()
21+
->symbols()
22+
->uncompromised(),
23+
],
24+
];
25+
}
26+
27+
public function attributes()
28+
{
29+
return [
30+
'first_name' => 'first name',
31+
'last_name' => 'last name',
32+
];
33+
}
34+
}

app/Models/User.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ class User extends Authenticatable
1818
use Notifiable;
1919

2020
protected $fillable = [
21-
'name',
21+
'first_name',
22+
'last_name',
2223
'email',
23-
'password',
2424
];
2525

2626
protected $hidden = [

composer.json

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,25 @@
55
"license": "MIT",
66
"require": {
77
"php": "^8.0.2",
8-
"guzzlehttp/guzzle": "^7.2",
8+
"guzzlehttp/guzzle": "^7.5",
99
"inertiajs/inertia-laravel": "^0.6.4",
10-
"laravel/framework": "^9.19",
11-
"laravel/sanctum": "^3.0",
12-
"laravel/tinker": "^2.7",
10+
"laravel/framework": "^9.43",
11+
"laravel/sanctum": "^3.0.1",
12+
"laravel/tinker": "^2.7.3",
1313
"tightenco/ziggy": "^1.5"
1414
},
1515
"require-dev": {
16-
"fakerphp/faker": "^1.9.1",
17-
"laravel/pint": "^1.0",
18-
"laravel/sail": "^1.0.1",
19-
"mockery/mockery": "^1.4.4",
20-
"nunomaduro/collision": "^6.1",
21-
"pestphp/pest": "^1.22",
16+
"fakerphp/faker": "^1.20",
17+
"laravel/pint": "^1.2.1",
18+
"laravel/sail": "^1.16.3",
19+
"mockery/mockery": "^1.5.1",
20+
"nunomaduro/collision": "^6.3.1",
21+
"pestphp/pest": "^1.22.3",
22+
"pestphp/pest-plugin-faker": "^1.0",
2223
"pestphp/pest-plugin-laravel": "^1.3",
2324
"pestphp/pest-plugin-parallel": "^1.2",
24-
"phpunit/phpunit": "^9.5.10",
25-
"spatie/laravel-ignition": "^1.0",
25+
"phpunit/phpunit": "^9.5.26",
26+
"spatie/laravel-ignition": "^1.6.1",
2627
"spatie/ray": "^1.36"
2728
},
2829
"autoload": {

0 commit comments

Comments
 (0)