我的问题是我无法搜索,也无法显示我的texbox中的值。
我想要的是搜索每个用户的id并将其数据显示到我的文本框中
我怎么能在这个视频上做到这一点?
到现在为止我有这个
这是我的网页This Video
查看

 {!! Form::open(['action' => 'Admin\EmployeeFilemController@search', 'method' => 'POST', 'enctype' => 'multipart/form-data']) !!}

                    <input type="text" name="id" class="form-control" placeholder="Enter ID to Search"><br>
                    <input type="submit" class="btn btn-primary btn-md" name="search" value="Search Data">
      {!! Form::close() !!}

控制器
   public function search(Request $request){
    $output = "";
    $employees = DB::table('employeefms')->where('id')->get();
    return redirect('/admin/employeemaintenance');
}

我的视图输入
 <div class="form-group col-md-2">
                {{Form::label('employee_no', 'Employee No.')}}
                {{Form::text('employee_no', '',['class' => 'form-control', 'placeholder' => 'Employee No.'])}}
        </div>

    <div class="row">
        <div class="form-group  col-md-4">
                {{Form::label('last_name', 'Last Name')}}
                {{Form::text('last_name', '',['class' => 'form-control', 'placeholder' => 'Last Name'])}}
        </div>

        <div class="form-group  col-md-4">
                    {{Form::label('first_name', 'First Name')}}
                    {{Form::text('first_name', '',['class' => 'form-control', 'placeholder' => 'First Name'])}}
        </div>
    </div>

    <div class="row">
        <div class="form-group  col-md-4">
                    {{Form::label('middle_name', 'Middle Name')}}
                    {{Form::text('middle_name', '',['class' => 'form-control', 'placeholder' => 'Middle Name'])}}
        </div>

        <div class="form-group  col-md-4">
                    {{Form::label('nick_name', 'Nick Name')}}
                    {{Form::text('nick_name', '',['class' => 'form-control', 'placeholder' => 'Nick Name'])}}
        </div>
    </div>

最佳答案

您似乎没有通过用户在控制器函数中输入的id

$employees = DB::table('employeefms')->where('id')->get();

您可能需要做以下更改
$input = $request->all();
$id = $input['id']
// $employees = DB::table('employeefms')->where('id', $id)->get();

// actually, if 'id' is the primary key, you should be doing
$employee = DB::table('employeefms')->find($id);

// now pass the data to the view where you want to display the record
// like so
return view('name_of_view', compact('employee'));

然后,使用Laravel的表单模型绑定
{!! Form::model($employee,
               ['action' => ['Admin\EmployeeFilemController@update', $employee->id],
               'method' => 'patch' // or whatever method you have defined
               ]) !!}

           // your form fields specified above will go here
{!! Form::close() !!}

关于php - 从文本框中的数据库搜索数据以显示-Laravel,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53644478/

10-11 05:21
查看更多