Laravel在模式窗口中显示视图

时间:2019-01-14 09:44:25

标签: laravel

感谢您的宝贵时间, 我对laravel应用有问题 有一个包含数据的表,每行都有一个链接到控制器操作的详细信息按钮,该操作在模式窗口中返回详细数据。

这是一个按钮代码

<button data-toggle="modal"  class="btn btn-primary" href="{{route('surveys.show',$sitedata->id)}}" data-target="#myModal">
                    <i class="fa fa-coffee"></i>
                  </button>   

这是控制器代码

public function show($id) 
{        
    $selectedSurveys = Survey::find($id)->where('site_data_id', $id)->get();

    return view('modals/survey-details')->with('selectedSurveys', $selectedSurveys);
}

这是路线

 Route::get('/surveys/{id}', 'SurveysController@show')->name('surveys.show');

这是视图模态/调查详细信息

<div class="modal-body">                        
<div class="box-body table-responsive">            
    <table class="table table-hover center">
        <tbody>
            <tr>
                <th>Email</th>
                <th>Response 1</th>
                <th>Response 2</th> 
                <th>Response 3</th>
                <th>Sent At</th>
                <th>Completed At</th>
            </tr>
            @foreach($selectedSurveys as $ss)
            <tr>
                <td>{{$ss->email}}</td> 
                <td>{{$ss->grade1}}</td>
                <td>{{$ss->grade2}}</td>
                <td>{{$ss->grade3}}</td>
                <td>{{$ss->created_at->format('d-M-Y ')}}</td>
                <td>@if(empty ($ss->updated_at))
                        Not Completed                   
                    @else
                        {{$ss->updated_at->format('d-M-Y ')}}                 
                    @endif
                </td>         
            </tr>
            @endforeach
        </tbody>
    </table>
</div>

index.blade表

<table class="table table-hover center" id="table_id">

                <thead>
                <tr>
                    <th>Studio</th>
                    <th>Month</th>
                    <th>Year</th>
                    <th>Satisfied Survey</th>
                    <th>SOS Reponse</th>  
                    <th>Ticket Management Quality</th>                       
                    <th>User Face to Face Survey</th>
                    <th>Opened</th>
                    <th>Closed</th>   
                    <th>Active</th>
                    <th>Actions</th>  
                    <th>Opened by</th>
                    <th>Updated by</th>           
                  </tr>                    
                </thead>
                <tbody>              
                  @foreach($sitesdata as $sitedata)
                  <tr>
                    <td>{{$sitedata->site->name}}</td>
                    <td>{{$sitedata->month}}</td>
                    <td>{{$sitedata->year}}</td>
                    <td>{{$sitedata->satisfaction}}</td>
                    <td>{{$sitedata->response}}</td>
                    <td>{{$sitedata->management}}</td>     
                    <td>{{$sitedata->survey}}</td>
                    <td>{{$sitedata->opened}}</td>
                    <td>{{$sitedata->closed}}</td>       
                    <td>{{$sitedata->active}}</td> 
                    <td data-id="{{$sitedata->id}}" data-user="{{auth()->user()->id}}">
                      <button data-toggle="modal" data-target="#edit-item" class="btn btn-primary edit-item"><i class="fa fa-edit"></i></button>
                      @if(in_array($sitedata->id, $sentSurveys))                      
                      <button data-toggle="modal"  class="btn btn-primary" href="{{route('surveys.show',$sitedata->id)}}" data-target="#myModal">
                        <i class="fa fa-coffee"></i>
                      </button>   

                      @else
                      <button data-toggle="modal" data-target="#send-mail" class="btn btn-primary send-mail"><i class="fa fa-envelope"></i></button>
                      @endif
                    </td>                  
                    <td>{{$sitedata->user->name}}<br>{{Carbon\Carbon::parse($sitedata->created_at)->format('d.m.Y H.i')}}</td>
                    @if($sitedata->modified_by != null)
                    <td>{{$users->firstWhere('id', $sitedata->modified_by)->name}}<br>{{Carbon\Carbon::parse($sitedata->updated_at)->format('d.m.Y H.i')}}</td> 
                    @else 
                    <td>Not updated yet</td> 
                    @endif                 
                  </tr>
                  @endforeach
                </tbody>
                <tfoot>
                  <tr>
                    <th>Studio</th>
                    <th>Month</th>
                    <th>Year</th>
                  </tr>
                </tfoot>
              </table>

该按钮有效,它获取数据并将其显示在模态中,但是当我单击另一行上的按钮时,它将显示第一行中的数据。

在laravel望远镜中,即使我按了所有按钮,我也只收到1个对SurveysController @ show的请求,要获取新数据,我必须重新加载页面

请帮助,我不知道该怎么尝试

1 个答案:

答案 0 :(得分:0)

如果您熟悉Vue,则可以将方法@click添加到行

<td @click="showModal(sitedata)">
export default {
    data() {
        return {
            modalData: false,
        }
    },

    methods: {
        showModal(sitedata) {
           this.modalData = sitedata
           $('#yourModalId').modal('show');
        }
    }
}