From c25933a7c048d3d936b7e2a8994e2f2d3c400b86 Mon Sep 17 00:00:00 2001 From: Bayu Cakra Date: Tue, 24 Oct 2017 22:32:48 +0700 Subject: [PATCH 1/3] add select role & contact number in register --- .../Controllers/Auth/RegisterController.php | 4 +++ app/User.php | 2 +- resources/views/auth/register.blade.php | 33 +++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index f77265a..c3a8038 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -50,6 +50,8 @@ protected function validator(array $data) return Validator::make($data, [ 'name' => 'required|string|max:255', 'email' => 'required|string|email|max:255|unique:users', + 'contact_number' => 'required|string|max:20', + 'role' => 'required', 'password' => 'required|string|min:6|confirmed', ]); } @@ -65,6 +67,8 @@ protected function create(array $data) return User::create([ 'name' => $data['name'], 'email' => $data['email'], + 'contact_number' => $data['contact_number'], + 'role' => $data['role'], 'password' => bcrypt($data['password']), ]); } diff --git a/app/User.php b/app/User.php index 5a43e9f..796da01 100644 --- a/app/User.php +++ b/app/User.php @@ -15,7 +15,7 @@ class User extends Authenticatable * @var array */ protected $fillable = [ - 'name', 'email', 'password', + 'name', 'email', 'contact_number', 'role', 'password', ]; /** diff --git a/resources/views/auth/register.blade.php b/resources/views/auth/register.blade.php index 38eef83..d0a996d 100644 --- a/resources/views/auth/register.blade.php +++ b/resources/views/auth/register.blade.php @@ -39,6 +39,39 @@ +
+ + +
+ + + @if ($errors->has('contact_number')) + + {{ $errors->first('contact_number') }} + + @endif +
+
+ +
+ + +
+ + + @if ($errors->has('role')) + + {{ $errors->first('role') }} + + @endif +
+
+
From 0f65a7daf6ac1f6b6eda53a99f0bb2ea44fd8181 Mon Sep 17 00:00:00 2001 From: Bayu Cakra Date: Tue, 24 Oct 2017 22:33:20 +0700 Subject: [PATCH 2/3] migration add new field called contact number --- ...0_24_151222_add_contactnumber_to_users.php | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 database/migrations/2017_10_24_151222_add_contactnumber_to_users.php diff --git a/database/migrations/2017_10_24_151222_add_contactnumber_to_users.php b/database/migrations/2017_10_24_151222_add_contactnumber_to_users.php new file mode 100644 index 0000000..9227f89 --- /dev/null +++ b/database/migrations/2017_10_24_151222_add_contactnumber_to_users.php @@ -0,0 +1,32 @@ +string('contact_number', 20)->after('email'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('users', function (Blueprint $table) { + $table->dropColumn('contact_number'); + }); + } +} From a0b5c1575527dbf46c6bfb1b3dd725cab409c30e Mon Sep 17 00:00:00 2001 From: Bayu Cakra Date: Tue, 24 Oct 2017 22:53:04 +0700 Subject: [PATCH 3/3] add custom route for new register --- app/Http/Controllers/Auth/RegisterController.php | 7 +++++++ routes/web.php | 1 + 2 files changed, 8 insertions(+) diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index c3a8038..4fcef3a 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -6,6 +6,7 @@ use App\Http\Controllers\Controller; use Illuminate\Support\Facades\Validator; use Illuminate\Foundation\Auth\RegistersUsers; +use App\Role; class RegisterController extends Controller { @@ -39,6 +40,12 @@ public function __construct() $this->middleware('guest'); } + public function index() + { + $roles = Role::all(); + return view('auth.register', compact('roles')); + } + /** * Get a validator for an incoming registration request. * diff --git a/routes/web.php b/routes/web.php index e186531..1e9f046 100644 --- a/routes/web.php +++ b/routes/web.php @@ -16,6 +16,7 @@ }); Auth::routes(); +Route::match(['get'], 'register', 'Auth\RegisterController@index')->name('register'); Route::get('/home', 'HomeController@index')->name('home');