Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add roles and contact number in register #27

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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.
*
Expand All @@ -50,6 +57,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',
]);
}
Expand All @@ -65,6 +74,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']),
]);
}
Expand Down
2 changes: 1 addition & 1 deletion app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class User extends Authenticatable
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
'name', 'email', 'contact_number', 'role', 'password',
];

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddContactnumberToUsers extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->string('contact_number', 20)->after('email');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('contact_number');
});
}
}
33 changes: 33 additions & 0 deletions resources/views/auth/register.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,39 @@
</div>
</div>

<div class="form-group{{ $errors->has('contact_number') ? ' has-error' : '' }}">
<label for="contact_number" class="col-md-4 control-label">Contact Number</label>

<div class="col-md-6">
<input id="contact_number" type="number" class="form-control" name="contact_number" value="{{ old('contact_number') }}" required>

@if ($errors->has('contact_number'))
<span class="help-block">
<strong>{{ $errors->first('contact_number') }}</strong>
</span>
@endif
</div>
</div>

<div class="form-group{{ $errors->has('role') ? ' has-error' : '' }}">
<label for="role" class="col-md-4 control-label">Role</label>

<div class="col-md-6">
<select name="role" id="role" class="form-control" required>
<option value="">Select role..</option>
@foreach($roles as $role)
<option value="{{ $role->id }}" {{ (Request::old('role') == $role->id) ? 'selected':'' }}>{{ $role->role }}</option>
@endforeach
</select>

@if ($errors->has('role'))
<span class="help-block">
<strong>{{ $errors->first('role') }}</strong>
</span>
@endif
</div>
</div>

<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label for="password" class="col-md-4 control-label">Password</label>

Expand Down
1 change: 1 addition & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
});

Auth::routes();
Route::match(['get'], 'register', 'Auth\RegisterController@index')->name('register');

Route::get('/home', 'HomeController@index')->name('home');

Expand Down