Laravel FORM ::选择不在网页中显示

时间:2017-02-23 07:35:58

标签: forms laravel select

创建注册页面时,我试图将数组从数据库('id'和'name')传入注册表单上的选择字段框,但是当我检查时它不会显示任何内容,它真的是bazar它在浏览器中我可以在正确的字段中正确看到div容器和所有选项但由于某种原因没有选择字段(总在浏览器中不可见)大声笑,我尝试使用硬编码值和数据库来自db和什么都没有让选择字段工作,非常感谢任何帮助!

select field

enter image description here

login.blade.php

@extends('layouts.main')

@section('content')
    <div class="page-footer" id="contactus">
        <div class="container">
            <div class="row" align="center">
                <div class="col 16 s12">
                    <h4 class="black-text">Account Center</h4>
                </div>
            </div>
            <div class="row" style="margin-bottom: 0px;">
                <div class="col 16 s12 m6" align="center">
                    <h5 class="black-text">Login</h5>
                    {!! Form::open(['method'=>'POST', 'action'=>'UsersController@store', 'class'=>'pure-form pure-form-stacked']) !!}
                    <br/>
                    <div class="input-field">
                        <i class="material-icons prefix fa fa-at"></i>
                        {!! Form::label('loginEmail', 'E-mail') !!}
                        {!! Form::email('loginEmail', null, ['class'=>'form-control'])!!}
                    </div>

                    <div class="input-field">
                        <i class="material-icons prefix fa fa-key"></i>
                        {!! Form::label('loginPassword', 'Password') !!}
                        {!! Form::password('loginPassword', ['class'=>'form-control'])!!}
                    </div>

                    <div class="form-group">
                        {!! Form::button('<i class="material-icons left fa fa-send"></i>Login', ['type' => 'submit', 'class'=>'waves-effect waves-light btn']) !!}
                    </div>

                    {!! Form::close() !!}
                    <br/><br/>
                </div>

                <div class="col 16 s12 m6" align="center">
                    <h5 class="black-text">Register</h5>
                    {!! Form::open(['method'=>'POST', 'action'=>'UsersController@store', 'class'=>'pure-form pure-form-stacked']) !!}
                    <br/>
                    <div class="input-field">
                        <i class="material-icons prefix fa fa-at"></i>
                        {!! Form::label('registerEmail', 'E-mail') !!}
                        {!! Form::email('registerEmail', null, ['class'=>'form-control'])!!}
                    </div>

                    <div class="input-field">
                        <i class="material-icons prefix fa fa-key"></i>
                        {!! Form::label('registerPassword', 'Password') !!}
                        {!! Form::password('registerPassword', ['class'=>'form-control'])!!}
                    </div>

                    <div class="input-field">
                        <i class="material-icons prefix fa fa-key"></i>
                        {!! Form::label('confirm', 'Confirm Password') !!}
                        {!! Form::password('confirm', ['class'=>'form-control'])!!}
                    </div>

                    <div class="input-field">
                        <i class="material-icons prefix fa fa-building"></i>
                        {!! Form::label('role_id', 'Role') !!}
                        </br>
                        {!! Form::select('role_id', [''=>'Choose Option'] + $organizationTypes, null, ['class'=>'form-control', 'style'=>' resize:vertical; ', 'id' => 'industryId'])!!}
                    </div>
                    </br>
                    </br>
                    </br>
                    </br>

                    <div class="input-field">
                        <i class="material-icons prefix fa fa-building"></i>
                        {!! Form::label('organizationName', 'Organization Name') !!}
                        {!! Form::password('organizationName', ['class'=>'form-control'])!!}
                    </div>

                    <div class="form-group">
                        {!! Form::button('<i class="material-icons left fa fa-send"></i>Register', ['type' => 'submit', 'class'=>'waves-effect waves-light btn']) !!}
                    </div>

                    {!! Form::close() !!}
                        <!-- loading spinner -->
                        <div class="preloader-wrapper active" id="sendEmailLoader">
                            <div class="spinner-layer spinner-yellow-only">
                                <div class="circle-clipper left">
                                    <div class="circle"></div>
                                </div>
                                <div class="gap-patch">
                                    <div class="circle"></div>
                                </div>
                                <div class="circle-clipper right">
                                    <div class="circle"></div>
                                </div>
                            </div>

                        </div>
                        <!-- end loader -->
                    </form>
                    <br/><br/>
                </div>

            </div>
        </div>

    </div>
@endsection

AuthController.php

<?php

namespace App\Http\Controllers\Auth;

use App\OrganizationType;
use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

class AuthController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Registration & Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users, as well as the
    | authentication of existing users. By default, this controller uses
    | a simple trait to add these behaviors. Why don't you explore it?
    |
    */

    use AuthenticatesAndRegistersUsers, ThrottlesLogins;

    /**
     * Where to redirect users after login / registration.
     *
     * @var string
     */
    protected $redirectTo = '/users';

    /**
     * Create a new authentication controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware($this->guestMiddleware(), ['except' => 'logout']);
    }

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'email' => 'required|email|max:255|unique:users',
            'password' => array(
                'required',
                'min:6',
                'confirmed',
                'regex:/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*(_|[^\w])).+$/'
            ),
            'organizationType' => 'required',
            'organizationName' => 'required|max:255',
        ]);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array $data
     * @return User
     */
    protected function create(array $data)
    {
        return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
        ]);
    }

    public function getLogin()
    {
        //
        $organizationTypes = OrganizationType::lists('name','id')->all();
        //return $organizationTypes;
        return view('auth.login', compact('organizationTypes'));
    }
}

routes.php文件

Route::get('/login', 'Auth\AuthController@getLogin');

1 个答案:

答案 0 :(得分:1)

方法lists()已弃用,请改用pluck()。

让你的选择做到这一点:

在你的控制器中首先更改列表()以采取()(我希望你有laravel版本5.2 +)

$organizationTypes = OrganizationType::pluck('name','id')->toArray();

并在视野中执行此操作

{!! Form::select('role_id', $organizationTypes, null, ['class'=>'form-control'])!!}

更新

好的,你正在使用css模板实现,并且由于模板,你需要为选择框附加正确的类...这将起作用,但也可能需要一些其他类:

{!! Form::select('role_id', $organizationTypes, null, ['class' => 'browser-default', 'placeholder' => 'Choose Option'])!!}
{!! Form::label('role_id', 'Organization name') !!}