【发布时间】:2019-06-08 06:58:09
【问题描述】:
感谢您的宝贵时间, 我有一个 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 的请求,要获取新数据,我必须重新加载页面
请帮忙,我不知道该尝试什么
【问题讨论】:
-
当您单击该行时,您的模式需要更新。因为它不是动态的。更好地显示您的完整 HTML。
-
添加了表格代码,我怎样才能使模态动态化,也许可以指点一下如何实现这一点?
-
@RobertB 为此目的使用 jquery ajax
-
getbootstrap.com/docs/4.0/components/modal/… 可以帮助您使用 jQuery 和 Ajax 更改模态内容。这样会更容易。
-
感谢您的想法,在打开模式时使用 ajax 加载视图。你的想法给了我更多研究的起点。祝你有美好的一天
标签: laravel