如何通过文本字段值循环记录

时间:2016-07-02 17:01:04

标签: php laravel twitter-bootstrap-3 laravel-5.2

如果用户点击修改按钮,我正在考虑如何在文本字段中循环记录。我有 搜索 刀片模板,其中记录列表已放入表格数据中。

search.blade.php

<table class = "table">
<br>
<thead>
<tr>
    <th>ID</th>
    <th>Firstname</th>
    <th>Lastname</th>
    <th>Middlename</th>
    <th>Email</th>
    <th>Username</th>
    <th>Actions</th>
</tr>

</thead>


<tbody>
@foreach ($data as $row)
    <tr class = "success">
        <td>{{ $row->id }}</td>
        <td>{{ $row->first_name }}</td>
        <td>{{ $row->last_name }}</td>
        <td>{{ $row->middle_name }}</td>
        <td>{{ $row->email }}</td>
        <td>{{ $row->username }}</td>
        <td>
            <a href = "{{ route ('account.edit', $row->id) }}"><button type = "submit" class = "btn btn-warning">Edit</button></a>
            <a href = "#"><button type = "submit" class = "btn btn-danger">Archive</button></a>
        </td>
    </tr>
@endforeach
</tbody>

我还在id视图中循环显示用户表的account.edit,以便知道选择了哪个ID。

路线:

//READ
Route::get('/search',
[
    'uses' => '\App\Http\Controllers\AccountController@getEmployee',
    'as' => 'account.search',
]);


//EDIT
Route::get('/edit/{id}',
[
    'uses' => '\App\Http\Controllers\AccountController@editEmployee',
    'as' => 'account.edit',
]);

控制器:

//READ
public function getEmployee()
{
    $result = DB::table('users')->get();

    return view ('account.search')->with('data', $result);
}


//EDIT
public function editEmployee($id)
{
    $result = User::find($id);

    return view ('account.edit')->with('data', $result);
}

我停留的这部分仍然不知道我将在 编辑 刀片模板中循环每个表格属性,遗憾的是它会给我一个错误。< / p>

  

缺少[Route:account.edit] [URI:edit / {id}]所需的参数。 (查看:C:\ Users \ JohnFrancis \ LaravelFrancis \ resources \ views \ account \ edit.blade.php)

<form class = "form-vertical" role = "form" method = "post" action = "{{ route ('account.edit') }}">

<h3>Edit Employee</h3>
<hr>

<div class = "form-group">

    <label for = "email" class = "control-label">Email Address</label>
    <input type = "text" name = "email" class = "form-control" value = "{{ $result->email }}">

</div>

<div class = "form-group">

    <label for = "username" class = "control-label">Username</label>
    <input type = "text" name = "username" class = "form-control" value = "{{ $result->username }}">

</div>

<div class = "form-group">

    <button type = "submit" class = "btn btn-success">Save</button> 

</div>

<input type = "hidden" name = "id" value = "{{ $result->id }}">
<input type = "hidden" name = "_token" value = "{{ Session::token() }}">

</form>

1 个答案:

答案 0 :(得分:0)

可能你错过了这个部分的id paraveter action = "{{ route ('account.edit') }}" 它应该是这样的 action = "{{ route ('account.edit', $result->id) }}"