我有一个表格,想为每一行添加一个 "查看详情 "按钮,链接到进一步的详情页,我已经很容易添加了这个按钮,但我想寻求一点帮助,使它能够打开与它相关的特定消息。
我的当前视图:
@extends ('layout')
@section('content')
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="/filtering.js"></script>
<link href="https://nightly.datatables.net/css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
<script src="https://nightly.datatables.net/js/jquery.dataTables.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.js"> </script>
<script src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/fixedheader/3.1.6/js/dataTables.fixedHeader.min.js"></script>
<div class="row align-items-center">
<div class="col">
<h1>
MESSAGES R US
</h1>
</div>
<div class="col ">
<a href="/create" class="btn btn-primary">CREATE MESSAGE</a>
</div>
<div class="col ">
<a href="/details" class="btn btn-primary">VIEW DETAILS</a>
</div>
</div>
<div class="form-group"> <!-- This works-->
<table id="userTable" data-page-length='5' cellspacing="0"
class="table table-bordered table-striped table-hover table-condensed"
role="grid">
<thead>
<tr>
<th scope="col">CREATED</th>
<th scope="col">USERNAME</th>
<th scope="col">TO/FROM</th>
<th scope="col">UPDATED</th>
<th scope="col">MESSAGE ID</th>
<th scope="col">STATUS</th>
<th scope="col">ACTION</th>
</tr>
</thead>
<tbody>
@foreach ($messages as $message)
<tr>
<td>{{$message->created_at}}</td>
<td>{{$message->username}}</td>
<td class="text-center">
@if ($message->direction == 'from')
<span class='badge badge-warning'>from</span>
@else
<span class='badge badge-success'>{{$message->direction}}</span>
@endif
</td>
<td>{{$message->updated_at}}</td>
<td>{{$message->message_id}}</td>
<td class="text-center">
@if ($message->status == 'FAIL')
<span class='badge badge-danger'>FAIL</span>
@elseif ($message->status == 'received')
<span class='badge badge-info'>received</span>
@elseif ($message->status == 'delivered')
<span class='badge badge-primary'>delivered</span>
@elseif ($message->status == 'queued')
<span class='badge badge-warning'>queued</span>
@elseif ($message->status == 'read')
<span class='badge badge-success'>read</span>
@endif
</td>
</td>
<td>
<div class="col "><a href="/details" class="btn btn-primary">VIEW</a></div>
</td>
</tr>
@endforeach
</tbody>
</table>
</div
@endsection
我在Laravel中建立了这个视图, 当点击视图时, 它只是显示同一个表格, 而没有具体到消息的行, 我不知道如何链接它来进一步显示MESSAGE ID的详细信息. 这是一个休闲项目,所以请原谅我的格式和UI。我是laravel新手,之前使用的是ASP.NET MVC。希望得到任何帮助。
我明白了我需要使它工作的概念。使用message_ID作为按钮的键,然后利用该表的数据(MESSAGE_ID - MESSAGE_TEXT),我只是需要帮助来连接这些点。)
首先,你必须在你的路由中声明 "详细信息路由"。你的路径可能是这样的
Route::get('/message/{id}/details', 'YourController@details')->name('message.detail');
然后在你的视图中,按钮将被调用这条路线,所以你的按钮视图将是这样的
<a href="{{ route('message.detail', $message->id) }}" class="btn btn-primary">VIEW</a>
你必须在路由中声明一个方法(在我的例子中,方法名称是 "details")。
public function details(Request $request, $id){
// your detail code here
}