English 中文(简体)
3. 用户的所有谈话和在拉拉维尔的方框中展示
原标题:Get all conversations by user and display in inbox view in Laravel

I m 为网站用户信息提供基本用户,使登记用户能够相互传递私人信息。 现在,我试图显示我(目前是用户)与其他用户的所有谈话。 并定期在方框中展示这些内容,与其他用户名称和照片以及每次谈话中的最新信息。

我有3个表格。

<>光线>

id
deleted_at

<>参与>

id
thread_id
user_id
blocked

http://www.ohchr.org。

id
thread_id
user_id
body

我已设法在我(目前用户)与另一个用户之间的单一谈话中开展工作。 但是,我很难在方框中展示我与其他用户的所有谈话。

如何最有效地检索我的所有谈话并在方框中展示,以及我自己的信息或其他用户信息谈话的最新信息?

问题回答

这里是未经测试的法典,可以把你置于正确的方向。

http://www.ohchr.org。

界定你模式中的关系。 假设你有三种模式:阅读、参与、电传和用户模式,界定了这种关系:

// User.php
public function threads()
{
    return $this->belongsToMany(Thread::class,  participants ,  user_id ,  thread_id );
}

// Thread.php
public function participants()
{
    return $this->hasMany(Participant::class);
}

public function messages()
{
    return $this->hasMany(Message::class);
}

// Message.php
public function thread()
{
    return $this->belongsTo(Thread::class);
}

阅读更多关于以下关系的内容:

www.un.org/Depts/DGACM/index_spanish.htm Retrieve threads

• 重新检索现有用户的线索及其最新信息:

$userId = auth()->id();

$threads = Thread::whereHas( participants , function ($query) use ($userId) {
    $query->where( user_id , $userId);
})
->with([ messages  => function ($query) {
    $query->latest()->first();
}])
->get();

这一询问发现,目前用户是参与者的所有线索,急切地将最新的信息输入每个线上。

<>分流>

@foreach ($threads as $thread)
    @foreach ($thread->participants as $participant)
        @if ($participant->user_id !== $userId)
            <div>
                <span>{{ $participant->user->name }}</span>
                <p>{{ $thread->messages->first()->body }}</p>
            </div>
        @endif
    @endforeach
@endforeach




相关问题
Table of calificacions in php and laravel

I created a table in order to show the name of the students, name of the subjects and the grade of the subject of the student I have the next code: this is the index part <form action="{{ ...

How to fix CORS for Capacitor/Quasar App in a Laravel API

I have an App built on top of Quasar and Capacitor, with an API built on top of Laravel. Everything works well on the dev environment until I build and install the app on my phone, then I keep getting ...

Laravel +Vuejs CORS issue

I am facing a dilemma wit the CORS issue. I have application that is configured as follow: API: https://abc.mydomain.com (laravel) front end: https://subdomain.mydomain.com(VueJS) Both applications ...

Laravel wrong redirecting to login page after login

In a multi tenancy with subdomain enviroment (http://zapburger.dex.local) when user fills login form with valid data and make login, laravel redirect to dashboard route (as expected) and then redirect ...

热门标签