duanshan5259 2016-07-02 17:01
浏览 23

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

I'm thinking how can I loop my records through textfield if the user hit the Edit button. I have search blade template where the list of records has put in the table data.

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>

I loop also the id of the Users table in my account.edit view so it will know which id is selected.

Routes:

//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',
]);

Controller:

//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);
}

This part where I stuck still do not have a idea where I'm gonna loop each table attributes in my edit blade template unfortunately it gives me a error.

Missing required parameters for [Route: account.edit] [URI: edit/{id}]. (View: C:\Users\JohnFrancis\LaravelFrancisesources\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条回答 默认 最新

  • dounan4479 2016-07-02 17:25
    关注

    Probably you missed an id paraveter at this part action = "{{ route ('account.edit') }}" It should be like this action = "{{ route ('account.edit', $result->id) }}"

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题