问题
I read the tutorial here : http://labs.infyom.com/laravelgenerator/docs/5.3/installation
I clone the admin lte generator : https://github.com/InfyOmLabs/adminlte-generator/tree/5.3
I access it in my localhost. The register form like this : https://postimg.org/image/5gswtx4gn/
I want to add some text field and combo box. eg, level, level, username etc
When I access the code, I\'m confused The code is like this :
Controller register is like this :
<?php
namespace App\\Http\\Controllers\\Auth;
use App\\User;
use Validator;
use App\\Http\\Controllers\\Controller;
use Illuminate\\Foundation\\Auth\\RegistersUsers;
class RegisterController extends Controller
{
use RegistersUsers;
protected $redirectTo = \'/home\';
public function __construct()
{
$this->middleware(\'guest\');
}
protected function validator(array $data)
{
return Validator::make($data, [
\'name\' => \'required|max:255\',
\'email\' => \'required|email|max:255|unique:users\',
\'password\' => \'required|min:6|confirmed\',
]);
}
protected function create(array $data)
{
return User::create([
\'name\' => $data[\'name\'],
\'email\' => $data[\'email\'],
\'password\' => bcrypt($data[\'password\']),
]);
}
}
It\'s load registeruser in vendor. It\'s like this :
<?php
namespace Illuminate\\Foundation\\Auth;
use Illuminate\\Http\\Request;
use Illuminate\\Support\\Facades\\Auth;
use Illuminate\\Auth\\Events\\Registered;
trait RegistersUsers
{
use RedirectsUsers;
public function showRegistrationForm()
{
return view(\'auth.register\');
}
public function register(Request $request)
{
$this->validator($request->all())->validate();
event(new Registered($user = $this->create($request->all())));
$this->guard()->login($user);
return $this->registered($request, $user)
?: redirect($this->redirectPath());
}
protected function guard()
{
return Auth::guard();
}
protected function registered(Request $request, $user)
{
//
}
}
The register view is like this :
<div class=\"register-box-body\">
<p class=\"login-box-msg\">Register a new membership</p>
<form method=\"post\" action=\"{{ url(\'/register\') }}\">
{!! csrf_field() !!}
<div class=\"form-group has-feedback{{ $errors->has(\'name\') ? \' has-error\' : \'\' }}\">
<input type=\"text\" class=\"form-control\" name=\"name\" value=\"{{ old(\'name\') }}\" placeholder=\"Full Name\">
<span class=\"glyphicon glyphicon-user form-control-feedback\"></span>
@if ($errors->has(\'name\'))
<span class=\"help-block\">
<strong>{{ $errors->first(\'name\') }}</strong>
</span>
@endif
</div>
<div class=\"form-group has-feedback{{ $errors->has(\'email\') ? \' has-error\' : \'\' }}\">
<input type=\"email\" class=\"form-control\" name=\"email\" value=\"{{ old(\'email\') }}\" placeholder=\"Email\">
<span class=\"glyphicon glyphicon-envelope form-control-feedback\"></span>
@if ($errors->has(\'email\'))
<span class=\"help-block\">
<strong>{{ $errors->first(\'email\') }}</strong>
</span>
@endif
</div>
<div class=\"form-group has-feedback{{ $errors->has(\'password\') ? \' has-error\' : \'\' }}\">
<input type=\"password\" class=\"form-control\" name=\"password\" placeholder=\"Password\">
<span class=\"glyphicon glyphicon-lock form-control-feedback\"></span>
@if ($errors->has(\'password\'))
<span class=\"help-block\">
<strong>{{ $errors->first(\'password\') }}</strong>
</span>
@endif
</div>
<div class=\"form-group has-feedback{{ $errors->has(\'password_confirmation\') ? \' has-error\' : \'\' }}\">
<input type=\"password\" name=\"password_confirmation\" class=\"form-control\" placeholder=\"Confirm password\">
<span class=\"glyphicon glyphicon-lock form-control-feedback\"></span>
@if ($errors->has(\'password_confirmation\'))
<span class=\"help-block\">
<strong>{{ $errors->first(\'password_confirmation\') }}</strong>
</span>
@endif
</div>
<div class=\"row\">
<div class=\"col-xs-8\">
<div class=\"checkbox icheck\">
<label>
<input type=\"checkbox\"> I agree to the <a href=\"#\">terms</a>
</label>
</div>
</div>
<!-- /.col -->
<div class=\"col-xs-4\">
<button type=\"submit\" class=\"btn btn-primary btn-block btn-flat\">Register</button>
</div>
<!-- /.col -->
</div>
</form>
<a href=\"{{ url(\'/login\') }}\" class=\"text-center\">I already have a membership</a>
</div>
I want to ask, how do I add a text field and a combo box on the form to register? I am confused. because the register view called from vendor(Illuminate\\Foundation\\Auth\\RegistersUsers)
回答1:
If you want to add some custom field to your registration process because your are using official laravel auth you can add your fields in : /resources/views/auth/register.blade.php
and then you can validate and save your inputs in : /app/Http/Controllers/Auth/RegisterController.php
you don't need to add anything to registeruser in vendor because every thing you add will change and replaced after every composer install or update.
来源:https://stackoverflow.com/questions/41030097/how-to-add-some-textfield-in-form-register-laravel-generator-infyom