Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.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
Laravel 5.5返回唯一值_Laravel_Laravel 5.5 - Fatal编程技术网

Laravel 5.5返回唯一值

Laravel 5.5返回唯一值,laravel,laravel-5.5,Laravel,Laravel 5.5,我创建了系统消息,当我有发送消息的用户和接收消息的用户时,我在一瞬间遇到了问题。如何返回一条消息,无论是谁发送的,谁接收的,以及这些消息有多少?我想要创建列表消息。我想创建一个消息列表,其中最后一条消息显示在列表中,单击它将显示整个对话 public function mymessages() { $user= Auth::user()->id; $messages = Messages::latest()->where('id_user_to_send',$u

我创建了系统消息,当我有发送消息的用户和接收消息的用户时,我在一瞬间遇到了问题。如何返回一条消息,无论是谁发送的,谁接收的,以及这些消息有多少?我想要创建列表消息。我想创建一个消息列表,其中最后一条消息显示在列表中,单击它将显示整个对话

  public function mymessages()
{

    $user= Auth::user()->id;
    $messages = Messages::latest()->where('id_user_to_send',$user)->orWhere('id_user_from',$user)->get();
    return $messages;
    return view('messages.inbox', compact('messages'));
}


public function up()
{
    Schema::create('messages', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('id_user_to_send')->unsigned();
        $table->integer('id_user_from')->unsigned();
        $table->string('text');
        $table->string('title');
        $table->foreign('id_user_to_send')->references('id')->on('users');
        $table->foreign('id_user_from')->references('id')->on('users');
        $table->timestamps();
    });
}
使用
first()
可以得到一个结果:

Messages::where('id_user_to_send',$user)
        ->orWhere('id_user_from',$user)
        ->orderBY('id', 'DESC')
        ->groupBY('id_conversation')
        ->first();

是的,但我不会给谈话留下一个结果。它是关于分组消息的。