如何在Laravel 5.3注册上添加动态下拉列表列? [英] How to add dynamic dropdown list column on Laravel 5.3 registration?

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

问题描述

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

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

我的registerusers(供应商)是这样的:

My registerusers(vendor) is 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 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(供应商)调用中出现了一个寄存器视图

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?

是否必须编辑registerusers(供应商)?

if I had to edit registerusers (vendor)?

如何?

推荐答案

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

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

此外,请勿在vendor目录中进行任何更改.

Also, do not make any changes in vendor directory.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆