doucheng3811 2017-08-16 09:19
浏览 19
已采纳

Laravel用户编辑

I have user details from DB and print using blade loop with button for edit. now I want, if I click button I need user details for the button which is clicked for user.

i tried with hidden input filed <input type="hidden" value="{{$user->email}}" name="email"> in my controller I just print the value from form submit. but I am getting only last user.

See below, I hope you will understand..

<div class="content-wrapper">
    <div class="flex-center position-ref full-height">
        <form action="{!!url('/delete')!!}" method="post"> {!!csrf_field()!!}   
            <div class="table-responsive">
                <table class="table table-hover">
                    <thead>
                      <tr>
                        <th>ID</th>
                        <th>Name</th>
                        <th>Email</th>
                        <th>Role</th>
                      </tr>
                    </thead>
                    <tbody>
                   @foreach($users as $user)
                      <tr>
                        <td>{{$user->id}}</td>
                        <td>{{$user->name}}</td>
                        <td>{{$user->email}}</td>   <input type="hidden" value="{{$user->email}}" name="email">
                        <td>{{$user->role}}</td>
                        <td>
                            <div class="btn-group">
                              <button type="submit" class="btn btn-primary btn-sm" name="edit"  >Edit</button>
                              <button type="submit" class="btn btn-primary btn-sm" name="delete"    >Delete</button>
                              <button type="submit" class="btn btn-primary btn-sm" name="make"  >Make Admin</button>
                            </div>
                        </td>
                      </tr>
                    @endforeach
                </tbody>
                </table>
            </div>  
        </form>     
    </div>
</div>  
  • 写回答

2条回答 默认 最新

  • doulizhi1247 2017-08-16 10:16
    关注

    Assuming that you want to go to edit page with a user's details when you click edit button.

    <a href="{{ route('your_route_name',$user->id) }}" class="test-btn btn btn-primary btn-sm">Edit</a>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?