Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel信息系统所有表格_Php_Mysql_Laravel - Fatal编程技术网

Php Laravel信息系统所有表格

Php Laravel信息系统所有表格,php,mysql,laravel,Php,Mysql,Laravel,我正在Laravel4中创建消息系统,我很困惑如何以这种方式从mysql检索数据 对于noy a,数据库中有3个表: conversations: id int A_I PRIMARY subject varchar 128 created_at datetime updated_at datetime conversations_messages: id

我正在Laravel4中创建消息系统,我很困惑如何以这种方式从mysql检索数据

对于noy a,数据库中有3个表:

conversations:
    id                int        A_I PRIMARY
    subject           varchar    128
    created_at        datetime
    updated_at        datetime

conversations_messages:
    id                int        A_I PRIMARY
    conversation_id   int
    user_id           int
    message           text
    created_at        datetime
    updated_at        datetime

conversations_members:
    conversation_id   int
    user_id           int
    last_view         int
    deleted           int
    created_at        datetime
    updated_at        datetime
在模型中:

Conversation.php

<?php
class Conversation extends Eloquent {
protected $table = 'conversations';

public function messages(){
    return $this->hasMany('ConversationMessage', 'conversation_id');
}
public function members(){
    return $this->hasMany('ConversationMember','conversation_id');
}   
}
?>
在我的控制器里,我到底该怎么做?或者如果有更好的方法,请帮忙

return View::make('messages.inbox')->with('conversation', ??????);
目前,我正在尝试使用查询生成器,但不知道如何使用

$con    = DB::table('conversations')
            ->select('id','subject')
            ->max('conversations_messages.created_at')->as('last_reply')
            ->from('conversations')
            ->leftJoin('conversations_messages',function($leftJoin){
                $leftJoin->on('conversations.id','=','conversations_messages.conversation_id');
            })
            ->join('conversations_members', function($join){
                $join->on('conversations.id','=','conversations_members.conversation_id');
            })
            ->where('conversations_members','=',Auth::user()->id)
            ->where('conversations_members.deleted','=',0)
            ->groupBy('cpnversation.id')
            ->orderBy('last_reply','dsc');

我提取了我提供的代码,因为在继续之前,您需要解决数据库结构和SQL查询的问题

SQL查询排除的是已删除的对话成员,而不是对话消息。如果希望能够排除已删除的消息,则在对话消息表中应该有一个表示已删除消息的字段


另外,我认为您可以完全不使用对话成员表。您已经在邮件中存储了该用户id,因此您已经知道谁正在参与对话。这里不需要另一个表。

那么您想要用户参与的所有对话吗?是的,我;我正在尝试使用查询生成器,但我不知道如何使用。Dtat deleted字段表示,如果用户删除消息,则消息将被删除。我不想向他显示该消息。explode()要求参数2为字符串,数组给定错误!我跟随这个guz是为了让它工作,但如何在拉雷维尔做到这一点?
SELECT
"conversations"."id",
"conversations"."subject",
MAX("conversations_messages"."created_at") AS "last_reply"
FROM "conversations"
LEFT JOIN "conversations_messages" ON "conversation"."id" = "conversations_messages"."conversation_id"
INNER JOIN "conversations_members" ON "conversations"."id" = "conversations_members"."conversation_id"
WHERE "conversations_members" = {Auth::user()->id}
AND "conversations_members"."deleted" = 0
GROPU BY "conversations"."id"
ORDER BY "last_reply" DESC
return View::make('messages.inbox')->with('conversation', ??????);
$con    = DB::table('conversations')
            ->select('id','subject')
            ->max('conversations_messages.created_at')->as('last_reply')
            ->from('conversations')
            ->leftJoin('conversations_messages',function($leftJoin){
                $leftJoin->on('conversations.id','=','conversations_messages.conversation_id');
            })
            ->join('conversations_members', function($join){
                $join->on('conversations.id','=','conversations_members.conversation_id');
            })
            ->where('conversations_members','=',Auth::user()->id)
            ->where('conversations_members.deleted','=',0)
            ->groupBy('cpnversation.id')
            ->orderBy('last_reply','dsc');