沃梦达 / 编程问答 / php问题 / 正文

如何在 Laravel 5.3 注册中添加动态下拉列表列?

How to add dynamic dropdown list column on Laravel 5.3 registration?(如何在 Laravel 5.3 注册中添加动态下拉列表列?)

本文介绍了如何在 Laravel 5.3 注册中添加动态下拉列表列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个下拉列表,其中从数据库中检索数据,即下拉级别.下拉级别的值取自表格级别.

我的寄存器控制器是这样的:

middleware('guest');}受保护的函数验证器(数组 $data){返回 Validator::make($data, ['名称' =>'需要|最大:255','用户名' =>'必需|唯一:用户','电子邮件' =>'required|email|max:255|unique:users','密码' =>'需要|分钟:6|已确认',]);}受保护的函数创建(数组 $data){返回用户::创建(['名称' =>$data['name'],'用户名' =>$data['用户名'],'电子邮件' =>$data['email'],'密码' =>bcrypt($data['password']),]);}}

我的注册用户(供应商)是这样的:

validator($request->all())->validate();事件(新注册($user = $this->create($request->all())));$this->guard()->login($user);返回重定向($this->redirectPath());}受保护的函数guard(){返回 Auth::guard();}}

我的注册视图是这样的:

{!!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="全名"><span class="glyphicon glyphicon-user form-control-feedback"></span>@if ($errors->has('name'))<span class="help-block"><strong>{{ $errors->first('name') }}</strong></span>@万一

<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>@万一

<div class="form-group has-feedback{{ $errors->has('password') ? ' has-error' : '' }}"><input type="password" class="form-control" name="password" placeholder="密码"><span class="glyphicon glyphicon-lock form-control-feedback"></span>@if ($errors->has('password'))<span class="help-block"><strong>{{ $errors->first('password') }}</strong></span>@万一

<div class="form-group has-feedback{{ $errors->has('password_confirmation') ?' has-error' : '' }}"><input type="password" name="password_confirmation" class="form-control" placeholder="确认密码"><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>@万一

<div class="row"><div class="col-xs-8"><div class="checkbox icheck"><标签><输入类型=复选框">我同意<a href="#">条款</a>

<!--/.col --><div class="col-xs-4"><button type="submit" class="btn btn-primary btn-block btn-flat">注册</button>

<!--/.col -->

</表单>

我得到了代码:https://github.com/InfyOmLabs/adminlte-发电机/树/5.3

代码中,在registerusers(vendor)的调用中出现了一个注册视图

如何调用数据库中的表存储在变量中并发送到查看寄存器?

如果我必须编辑注册用户(供应商)?

怎么做?

解决方案

如果我理解正确,您需要重写 showRegistrationForm() 方法.因此,将此方法从供应商复制粘贴到 RegisterController 并在那里使用它:

公共函数 showRegistrationForm(){//在这里做点什么.返回视图('auth.register');}

另外,不要在 vendor 目录中做任何更改.

I want to create a dropdown list where the data retrieved from the database, ie dropdown level. the value of the dropdown level is taken from the table level.

My register controller is like this :

<?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']),
        ]);
    }
}

My registerusers(vendor) is like this :

<?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();
    }
}

My register view is like this :

<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>

I get the code : https://github.com/InfyOmLabs/adminlte-generator/tree/5.3

of the code, it appears that a register view in the call of registerusers (vendor)

how to call a table in the database to be stored in variables and sent to view the register?

if I had to edit registerusers (vendor)?

How to?

解决方案

If I understood you correctly, you need to override showRegistrationForm() method. So, copy-paste this method from vendor to RegisterController and work with it there:

public function showRegistrationForm()
{
    // Do something here.

    return view('auth.register');
}

Also, do not make any changes in vendor directory.

这篇关于如何在 Laravel 5.3 注册中添加动态下拉列表列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何在 Laravel 5.3 注册中添加动态下拉列表列?

基础教程推荐