2016-02-16 28 views
0

我想創建一個網站,「視頻羣聊」的顯示,以及用戶可以點擊「加入」,並出席了活動。Laravel - 安裝「USER_ID」到「hangout_id」

我想讓它這樣,當用戶點擊加入,他們的USER_ID被附着在hangout_user透視表中的相關hangout_id。通過這樣做,他們的名字應該被追加到與會者列表的底部。

我試圖用一個表單提交附加user_ID的,但我敢肯定,我做到了不正確。

我怎麼能正確地創建這個連接按鈕?

網站的截圖 Screenshot of Website

代碼加入按鈕和顯示與會者

{!! Form::model($hangout['method' => 'PATCH', 'action' => ['[email protected]', $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的視頻羣聊

hangout_user pivot table

+0

你能解釋一下你在數據庫 –

+0

嗨Yagnik想這樣的結果 - 我編輯的職位以包含更多信息。希望這會有所幫助 – FLIMP

+0

爲什麼你不使用ajax作爲連接事件?爲相關的hangout_id添加user_id的相關表並添加新的ajax成功html並刪除已加入事件的連接按鈕。 –

回答

-1

你可以在你的Hangouts表中的列attendees。然後存儲與會者像這樣:

[0,2,5,7,18,21,4]

每個數字表示用戶名的ID。因此,基本上,當用戶「加入」視頻羣聊時,您會抓住整個視頻羣聊的參與者值,對其進行解碼,將用戶ID推入陣列,然後再次更新該值(當然編碼後)。

如果你不確定如何提交表單後執行的操作,它的完成,像這樣:

{!! Form::open(array('action' => '[email protected]')) !!} 
+0

阿里爾嗨 - 感謝您幫助。這將是比使用數據透視表和附加user_ID的線沿線的東西更容易... $ hangout->用戶() - >連接(AUTH ::用戶() - > ID)? – FLIMP