首页 > 解决方案 > 无法使用引导模型检​​索整个用户集合及其关系,我只收到单个用户及其关系

问题描述

我试图通过模型从数据库中检索用户详细信息,因此当我单击特定用户时,它会显示指定的用户以及所需的其他一些详细信息

我只使用引导模型,我不知道它是如何工作的,而且我对带有 jquery 的 javascript 了解不多,我只需要这个模型来完成所有事情

/* here is my blade */

@extends('inherit.admin')

@section('info')
@if(count($applieds)>0)
<div class="container">
<table class="table table-hover membertable" style="margin-top: 100px;">

    <tr>
        <th>Name</th>
        <th>Email</th>
        <th>Role</th>
        <th>Status</th>
        <th> Forms</th>
        <th>Actions</th>
        <th>View Applications</th>
    </tr>
    @foreach($applieds as $user)
    <tr>
        <td>{{$user->name}}</td>
        <td>{{$user->email}}</td>
        <td>{{$user->role->name}}</td>
        <td> @foreach ($user->post as $key=>$form) 
            @if($key == count($user->post)-1)
            <div class="text-muted" style="float: left;padding-right: 10px">
                <?php echo $form->pivot->status ?>
              </div>
             @endif
              @endforeach
</td>
<td>
     @foreach ($user->post as $key=>$form) 
            @if($key == count($user->post)-1)
             <a href="/downloads/{{$user->id}}"> <button class="btn btn-success" style="width: 100px" ><i class="fa fa-download"></i> Download form <?php echo $form->pivot->file ?></button></a>

             @endif

              @endforeach
</td>
<td><a href="/approve/{{$user->id}}"> <button class="btn btn-success">Approve</button></a> <a href="/reject/{{$user->id}}"> <button class="btn btn-danger">Reject</button></a></td>
<td>
         <!-- Trigger the modal with a button -->
  <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#applications">View applications</button>

  <!-- Modal -->
  <div class="modal fade" id="applications" role="dialog">
    <div class="modal-dialog">

      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          {{-- <button type="button" class="close" data-dismiss="modal">&times;</button> --}}
          <h4 class="modal-title">Applications</h4>
        </div>
        <div class="modal-body">
            <div class="text-muted" style="float: left;padding-right: 10px">
               @foreach($user->post as $form)
                    {{$form->pivot->company_name}}
               @endforeach
               {{$user->name}}
             </div>        
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>

    </div>
  </div>

</td>

    </tr>

    @endforeach
</table>
</div>


@endif
@endsection


/* my controller */

 public function index()
    {
        $applieds=User::where('role_id',4)->with('post')->get();

        return view('Applieds.index',compact('applieds'));
    }

没有错误,它只显示第一个用户的唯一两个详细信息,当我需要检索它时它只会重复它

标签: laravelbootstrap-modal

解决方案


您可以尝试使用以下代码: data-target="#applications_{{$user->id}}" 和 id="applications_{{$user->id}}"

 <!-- Trigger the modal with a button -->
  <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#applications_{{$user->id}}">View applications</button>

  <!-- Modal -->
  <div class="modal fade" id="applications_{{$user->id}}" role="dialog">
    <div class="modal-dialog">

      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          {{-- <button type="button" class="close" data-dismiss="modal">&times;</button> --}}
          <h4 class="modal-title">Applications</h4>
        </div>
        <div class="modal-body">
            <div class="text-muted" style="float: left;padding-right: 10px">
               @foreach($user->post as $form)
                    {{$form->pivot->company_name}}
               @endforeach
               {{$user->name}}
             </div>        
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>


推荐阅读