未捕获的TypeError:无法读取属性'标签'在laravel 5.4中为null

时间:2018-01-07 20:05:04

标签: javascript ajax laravel

实际上,我在我的输入中使用自动完成,数据来自enrolCourse表,如果我看到我的路径数据从数据库表返回我的表单中没有显示我的表单显示此错误。我正在上传我的表单代码和javascript代码



{!! Form::open(array('url' => '/admin/enrollCourse/store')) !!}
    <div class="col-md-12">
        <div class="panel panel-default">
            <div class="panel-heading"></div>
            <div class="panel-body">

                {!! Form::open(array('url' => '/admin/saveResult/create')) !!}
                <div class="col-md-12">
                    <div class="form-group">
                        {{Form::label('Student Register','Search Student Register Number')}}
                        {!! Form::text('reg_id', null, array('id'=>'reg_id','placeholder' => 'Search Registration Number','class' => 'form-control')) !!}
                    </div>
                </div>
                {!! Form::close()  !!}
                <div class="col-md-7">

                    <div class="form-group">
                        {{Form::label('Student Registration','Student Registration Number')}}
                        {!! Form::text('reg_number', null, array('id'=>'reg_number','placeholder' => ' Registration Number','class' => 'form-control')) !!}
                    </div>
                    <div class="form-group">
                        {{Form::label('Name','Student Name')}}
                        {!! Form::text('s_name', null, array('id'=>'s_name','placeholder' => 'Enter Student Name','class' => 'form-control')) !!}
                    </div>
                    <div class="form-group">
                        {{Form::label('Email','Student Email')}}
                        {!! Form::email('email', null, array('id'=>'email','placeholder' => 'Enter Student Email','class' => 'form-control')) !!}
                    </div>

                    <div class="form-group">
                        {{Form::label('Department','Department ')}}
                        {!! Form::text('department_id', null, array('id'=>'department_id','placeholder' => 'Enter Student Department','class' => 'form-control','onchange'=>"teacherQuery() ")) !!}
                        
                    </div>

                    <div class="form-group">
                        {{Form::label('Select Course','Select Course ')}}
                        {{csrf_field()}}
                        <select name="course_id" class="form-control" id="course_id">
                            <option value=" ">----Select Course-----</option>
                            
                        </select>
                    </div>


                    <div class="form-group">
                        {{Form::label('Select Grade','Select Grade ')}}
                        {{csrf_field()}}
                        <select name="grade_id" class="form-control" id="grade_id">
                            <option value=" ">----Select Course-----</option>
                            <option>A+</option>
                            <option>A</option>
                            <option>A-</option>
                            <option>B+</option>
                            <option>B</option>
                            <option>B-</option>
                            <option>C+</option>
                            <option>C</option>
                            <option>C-</option>
                            <option>D+</option>
                            <option>D</option>
                            <option>D-</option>
                        </select>
                    </div>

                    <div>
                        {{Form::submit('Enroll',['class'=>'btn btn-primary'])}}
                    </div>
                </div>


            </div>
        </div>
    </div>

    {!! Form::close() !!}


@endsection
@section('script')
    <script type="text/javascript">
        var dropdown = "<option value=''>----Select Course-----</option>";
        $('#reg_id').autocomplete({
            source: '{!!URL::route('autocomplete/result')!!}',
            minlenght: 1,
            autoFocus: true,
            select: function (e, ui) {
                $('#reg_number').val(ui.item.reg_num);
                $('#s_name').val(ui.item.s_name);
                $('#email').val(ui.item.email);
                $('#department_id').val(ui.item.department_name);
                for(var i=0;i<ui.item.course_id.length;i++){
                    dropdown +="<option value='"+ui.item.course_id[i].id+"'>"+ui.item.course_id[i].name+"</option>"
                }
                $('#course_id').html(dropdown);
                console.log(ui);
            }
        });



    </script>
@endsection
&#13;
&#13;
&#13;

和控制器代码在这里

public function  autocompleteResult(Request $request)
{
    $term = $request->term;
    $date = EnrollCourses::where('reg_num','LIKE','%' .$term. '%')->with('course')->take(10)->get();

    $result = array();
    foreach($date as $key=> $v)
    {
        $result = ['reg_num' =>$v->reg_num,'s_name'=>$v->s_name, 'email'=>$v->email,'department_id'=>$v->department_id, 'course_id'=>$v->course['name']];
    }
    return response()->json($result);
}

我需要你的帮助,请建议我,我该如何解决这个问题?

0 个答案:

没有答案