php – 如何在Laravel 5.3注册中添加动态下拉列表列?
发布时间:2020-12-14 19:34:00 所属栏目:大数据 来源:网络整理
导读:我想创建一个下拉列表,其中从数据库中检索数据,即下拉级别. 下拉级别的值取自表级别. 我的注册控制器是这样的: ?phpnamespace AppHttpControllersAuth;use AppUser;use Validator;use AppHttpControllersController;use IlluminateFoundationAuth
|
我想创建一个下拉列表,其中从数据库中检索数据,即下拉级别.
下拉级别的值取自表级别. 我的注册控制器是这样的: <?php
namespace AppHttpControllersAuth;
use AppUser;
use Validator;
use AppHttpControllersController;
use IlluminateFoundationAuthRegistersUsers;
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','username' => 'required|unique:users','email' => 'required|email|max:255|unique:users','password' => 'required|min:6|confirmed',]);
}
protected function create(array $data)
{
return User::create([
'name' => $data['name'],'username' => $data['username'],'email' => $data['email'],'password' => bcrypt($data['password']),]);
}
}
我的注册用户(供应商)是这样的: <?php
namespace IlluminateFoundationAuth;
use IlluminateHttpRequest;
use IlluminateSupportFacadesAuth;
use IlluminateAuthEventsRegistered;
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 redirect($this->redirectPath());
}
protected function guard()
{
return Auth::guard();
}
}
我的注册视图是这样的: <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>
我得到的代码:https://github.com/InfyOmLabs/adminlte-generator/tree/5.3 代码,看来在registerusers(供应商)的调用中的寄存器视图 如何在数据库中调用一个表来存储变量并发送到查看寄存器? 如果我必须编辑注册用户(供应商)? 如何? 解决方法
如果我理解正确,您需要覆盖showRegistrationForm()方法.因此,将此方法从供应商复制粘贴到RegisterController并在那里使用它:
public function showRegistrationForm()
{
// Do something here.
return view('auth.register');
}
此外,不要在供应商目录中进行任何更改. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
