Laravel 5.2未定义变量(选择下拉列表)

时间:2016-05-14 03:27:00

标签: laravel select

这是在InfoController中从数据库返回行的函数

protected function getInfo()
{
    $info = Info::where('status', '1')->orderBy('name')->lists('name', 'id');

    return view('registration.profile')->with('info', $info);

}

InfoController中的索引方法

public function index()
{
    return view('register/profile');
}

在我看来

{!! Form::open(array('url' => 'info')) !!}

                    <div class="form-group">
                        {{ Form::label('Info','Select an Option'), array('class' => 'col-md-4
                        control-label') }}
                        <div class="col-md-6">
                          {!! Form::select('Info', $info, null, ['class' => 'form-control']) !!}

                        </div>
                    </div>

                    <div class="form-group{{ $errors->has('pronunciation') ? ' has-error' : '' }}">
                        {{ Form::label('pronunciation', 'Pronunciation', array('class' => 'col-md-4 control-label')) }}

                        <div class="col-md-6">
                            {{ Form::text('pronunciation', old('pronunciation'), array('class' => 'form-control')) }}
                            @if ($errors->has('pronunciation'))
                                <span class="help-block">
                                        <strong>{{ $errors->first('pronunciation') }}</strong>
                                    </span>
                            @endif
                        </div>
                    </div>

                    <div class="form-group{{ $errors->has('dob') ? ' has-error' : '' }}">

                        {{ Form::label('dob', 'Date of Birth', array('class' => 'col-md-4 control-label')) }}

                        <div class="col-md-6">
                            {{ Form::text('dob', old('dob'), array('class' => 'form-control')) }}
                            @if ($errors->has('dob'))
                                <span class="help-block">
                                        <strong>{{ $errors->first('dob') }}</strong>
                                    </span>
                            @endif
                        </div>
                    </div>

                    <div class="form-group{{ $errors->has('phonePrimary') ? ' has-error' : '' }}">
                        {{ Form::label('phonePrimary', 'Primary Phone Number', array('class' => 'col-md-4
                        control-label')) }}

                        <div class="col-md-6">
                            {{ Form::text('phonePrimary', old('phonePrimary'), array('class' => 'form-control')) }}
                            @if ($errors->has('phonePrimary'))
                                <span class="help-block">
                                        <strong>{{ $errors->first('phonePrimary') }}</strong>
                                    </span>
                            @endif
                        </div>
                    </div>

                    <div class="form-group{{ $errors->has('phoneSecondary') ? ' has-error' : '' }}">
                        {{ Form::label('phoneSecondary', 'Secondary Phone Number', array('class' => 'col-md-4
                        control-label')
                        ) }}

                        <div class="col-md-6">
                        {{ Form::text('phoneSecondary', old('phoneSecondary'), array('class' =>'form-control',
                        'placeholder' => 'xxx-xxx-xxxx')) }}
                        @if ($errors->has('phoneSecondary'))
                            <span class="help-block">
                                        <strong>{{ $errors->first('phoneSecondary') }}</strong>
                                    </span>
                        @endif
                    </div>


                    <div class="form-group{{ $errors->has('addressLineOne') ? ' has-error' : '' }}">
                        {{ Form::label('addressLineOne', 'Address Line One', array('class' => 'col-md-4 control-label')) }}

                        <div class="col-md-6">
                            {{ Form::text('addressLineOne', old('addressLineOne'), array('class' => 'form-control')) }}
                            @if ($errors->has('addressLineOne'))
                                <span class="help-block">
                                        <strong>{{ $errors->first('addressLineOne') }}</strong>
                                    </span>
                            @endif
                        </div>
                    </div>

                    <div class="form-group{{ $errors->has('addressLineTwo') ? ' has-error' : '' }}">
                        {{ Form::label('addressLineTwo', 'Address Line Two', array('class' => 'col-md-4 control-label')) }}

                        <div class="col-md-6">
                            {{ Form::text('addressLineTwo', old('addressLineTwo'), array('class' =>
                            'form-control')) }}
                            @if ($errors->has('addressLineTwo'))
                                <span class="help-block">
                                        <strong>{{ $errors->first('addressLineTwo') }}</strong>
                                    </span>
                            @endif
                        </div>
                    </div>

                    <div class="form-group{{ $errors->has('addressProv') ? ' has-error' : '' }}">
                        {{ Form::label('addressProv', 'Province', array('class' => 'col-md-4
                        control-label')) }}

                        <div class="col-md-6">
                            {{ Form::text('addressProv', old('addressProv'), array('class' =>'form-control')) }}
                            @if ($errors->has('addressProv'))
                                <span class="help-block">
                                        <strong>{{ $errors->first('addressProv') }}</strong>
                                    </span>
                            @endif
                        </div>
                    </div>

                    <div class="form-group{{ $errors->has('addressProvOther') ? ' has-error' : '' }}">
                        {{ Form::label('addressProvOther', 'Other Province', array('class' => 'col-md-4 control-label')) }}

                        <div class="col-md-6">
                            {{ Form::text('addressProvOther', old('addressProvOther'), array('class' =>'form-control')) }}
                            @if ($errors->has('addressProvOther'))
                                <span class="help-block">
                                        <strong>{{ $errors->first('addressProvOther') }}</strong>
                                    </span>
                            @endif
                        </div>
                    </div>

                    <div class="form-group{{ $errors->has('addressCountry') ? ' has-error' : '' }}">
                        {{ Form::label('addressCountry', 'Country', array('class' => 'col-md-4 control-label')) }}

                        <div class="col-md-6">
                            {{ Form::text('addressCountry', old('addressCountry'), array('class' =>'form-control')) }}
                            @if ($errors->has('addressCountry'))
                                <span class="help-block">
                                        <strong>{{ $errors->first('addressCountry') }}</strong>
                                    </span>
                            @endif
                        </div>
                    </div>

                    <div class="form-group{{ $errors->has('addressCountryOther') ? ' has-error' : '' }}">
                        {{ Form::label('addressCountryOther', 'Other Country', array('class' => 'col-md-4 control-label')) }}

                        <div class="col-md-6">
                            {{ Form::text('addressCountryOther', old('addressCountryOther'), array('class' =>'form-control')) }}
                            @if ($errors->has('addressCountryOther'))
                                <span class="help-block">
                                        <strong>{{ $errors->first('addressCountryOther') }}</strong>
                                    </span>
                            @endif
                        </div>
                    </div>

                    <div class="form-group{{ $errors->has('emergencyRelationship') ? ' has-error' : '' }}">
                        {{ Form::label('emergencyRelationship', 'Relationship to Contact', array('class' => 'col-md-4 control-label')) }}

                        <div class="col-md-6">
                            {{ Form::text('emergencyRelationship', old('emergencyRelationship'), array('class' => 'form-control')) }}
                            @if ($errors->has('emergencyRelationship'))
                                <span class="help-block">
                                        <strong>{{ $errors->first('emergencyRelationship') }}</strong>
                                    </span>
                            @endif
                        </div>
                    </div>

                    <div class="form-group{{ $errors->has('emergencyContact') ? ' has-error' : '' }}">
                        {{ Form::label('emergencyContact', 'Name of Emergency Contact', array('class' => 'col-md-4 control-label')) }}

                        <div class="col-md-6">
                            {{ Form::text('emergencyContact', old('emergencyContact'), array('class' => 'form-control')) }}
                            @if ($errors->has('emergencyContact'))
                                <span class="help-block">
                                        <strong>{{ $errors->first('emergencyContact') }}</strong>
                                    </span>
                            @endif
                        </div>
                    </div>

                    <div class="form-group{{ $errors->has('emergencyNumber') ? ' has-error' : '' }}">
                        {{ Form::label('emergencyNumber', 'Contacts Phone Number', array('class' => 'col-md-4 control-label')) }}

                        <div class="col-md-6">
                            {{ Form::text('emergencyNumber', old('emergencyNumber'), array('class' => 'form-control')) }}
                            @if ($errors->has('emergencyNumber'))
                                <span class="help-block">
                                        <strong>{{ $errors->first('emergencyNumber') }}</strong>
                                    </span>
                            @endif
                        </div>
                    </div>

                    <div class="form-group{{ $errors->has('emergencyRelationship') ? ' has-error' : '' }}">
                        {{ Form::label('emergencyRelationship', 'Relationship to Contact', array('class' => 'col-md-4 control-label')) }}

                        <div class="col-md-6">
                            {{ Form::text('emergencyRelationship', old('emergencyRelationship'), array('class' => 'form-control')) }}
                            @if ($errors->has('emergencyRelationship'))
                                <span class="help-block">
                                        <strong>{{ $errors->first('emergencyRelationship') }}</strong>
                                    </span>
                            @endif
                        </div>
                    </div>

                    <div class="form-group">
                        {{ Form::label('notes', 'Notes', array('class' => 'col-md-4 control-label')) }}
                        <div class="col-md-6">
                            {{ Form::text('notes', old('notes'), array('class' => 'form-control')) }}
                        </div>
                    </div>

以下是来自route.php的所有路线

Route::get('/', function () {
    return view('/welcome');
});

Route::auth();

Route::get('/home', 'HomeController@index');

Route::resource('dept', 'DeptController');

Route::resource('info', 'InfoController');

Route::get('info', 'InfoController@getInfo');

Route::resource('userInfo', 'UserInfoController');

Route::resource('hc', 'HCController');

Route::resource('events', 'EventsController');

Info表有超过10个状态= 1

的条目

以下是我遇到的错误......它们太大而无法粘贴

错误2/2 http://pastebin.com/8qqA73A6     ec2da5a708f4be6fbaacda062c4e3a98ce5eb42c.php第24行中的ErrorException:未定义的变量:info(查看:......)

错误1/2 http://pastebin.com/rysZvcCt

ErrorException in ec2da5a708f4be6fbaacda062c4e3a98ce5eb42c.php line 24: Undefined variable: info

3 个答案:

答案 0 :(得分:1)

您即将结束Form ::标签

{{ Form::label('Info','Select an Option'), array('class' => 'col-md-4 control-label') }}

应该是

{{ Form::label('Info','Select an Option', array('class' => 'col-md-4 control-label')) }}

答案 1 :(得分:0)

Collection,query builder和Eloquent查询构建器对象上的lists方法已重命名为pluck。方法签名保持不变。

https://laravel.com/docs/5.2/upgrade

答案 2 :(得分:0)

with闪烁会话数据,它不会公开具有给定名称的变量。  以这种方式执行操作时,您的数据将在您的视图中可用,如下所示:

session('info')

你真正想要的是:

protected function getInfo()
{
    $info = Info::where('status', '1')->orderBy('name')->lists('name', 'id');
    return view('registration.profile', ['info' => $info]);
}