Wednesday 15 August 2012

laravel - Using Eloquent to create a new conversation -


I am writing a conversation system for my application using the Laravel framework. If I'm doing hard work in the database, then I can have a conversation at present.

Now, when I create a new conversation in a new conversation , then call me Conversations table and user and conversation_id to conversation_user .

How can I do this? I currently have the bottom.

I have 3 database tables

Conversation:

id |

Conversation_user:

id | Conversation_id | User_id

Message:

ID | Message | User_id | Conversation_id | Conversation made

I have 2 models

Conversation

  class conversation eloquent {public $ table = 'conversations'; Public $ includes = array ('user', 'message'); Public function user () {return $ this-> Affiliation Value ('User'); } Public Function Message () {Return $ this- & gt; Hayman ('message'); }}   

Message

  Class message spreads in headlines {public $ table = 'messages'; Public $ includes = array ('user', 'conversation'); Secure $ fillable = array ('message', 'user_id', 'conversation_id'); Public function user () {return $ this-> Affiliation ('user'); } Public function Conversation () {Return $ this- & gt; Association ('Conversation'); }}    

it worked

  $ conversation = Conversation :: Creating (array ()); $ Conversation- & gt; User () - & gt; (Sentry :: getUser () -> ID); $ Conversation- & gt; User () - & gt; Gave ($ id); $ Conversation- & gt; Save ();    

No comments:

Post a Comment