【发布时间】:2016-05-27 10:30:56
【问题描述】:
我想创建一个网站,其中显示“环聊”,用户可以点击“加入”并参加活动。
我想这样当用户点击加入时,他们的 user_id 会附加到 hangout_user 数据透视表中的相关 hangout_id。通过这样做,他们的名字应该被附加到与会者列表的底部。
我尝试使用表单提交来附加 user_id,但我很确定我做错了。
如何正确创建此加入按钮?
加入按钮和显示与会者的代码
{!! Form::model($hangout['method' => 'PATCH', 'action' => ['HangoutController@update', $hangout->id]]) !!}
<div class="form-group panel-footer" style="text-align:center">
{!! Form::submit('Join', ['class' => 'btn btn-primary', 'style'=>"width:45%"]) !!}
</div>
{!! Form::close() !!}
<table class="table">
<thead>
<tr>
<th style="width:33%;padding-left:3%">Attendees</th>
<th style="width:33%">First Name</th>
<th style="width:33%">Surname</th>
</tr>
</thead>
<tbody>
@foreach ($hangout->users as $user)
<tr>
<td style="padding-left:5%">{{1}}</td>
<td>{{$user->firstname}}</td>
<td>{{$user->surname}}</td>
</tr>
@endforeach
</tbody>
</table>
非常感谢您的宝贵时间:)
已编辑以添加更多详细信息
我追求的结果是数据透视表 hangout_user 具有 hangout_id 和 user_id 行。以下图为例,这意味着用户 1 将参加环聊 1 和环聊 2。
【问题讨论】:
-
你能解释一下你想在数据库中得到什么样的结果
-
嗨 Yagnik - 我已经编辑了帖子以包含更多信息。希望这会有所帮助
-
为什么不使用ajax 来加入活动 更新相关hangout_id 的相关表添加user_id 并放置ajax 成功的新html 并删除已经加入活动的加入按钮。跨度>
-
不幸的是,因为我不知道如何 :( 我对编程很陌生,所以在学习各种教程时仍在学习...请您指导我正确的方向吗?
标签: php mysql laravel relationship pivot-table