Counting Models related through manyToMany only if a pivot attribute null - Laravel

点点圈 提交于 2020-01-17 05:13:14
问题 I am elaborating code acquired here ManyToMany relation - how update attribute in pivot table what I want: I want to get a collection of Activities related to any weekly Routine . The pivot table's atribute done_at tells me when any activity (task) was completed. I can list and later ->count()

How to create follower relationships using Polymorphic Many to Many relationships with Laravel?

两盒软妹~` 提交于 2020-01-17 04:12:27
问题 Okay, so I'm trying to create a relationship where users can follow other users or follow categories. I got a recommendation to use Polomorpic Many to Many relationships. Right now I'm trying to create a follower - followee relationship but I can't wrap my head around how to set up the models and

Laravel Eloquent distinct values

时光毁灭记忆、已成空白 提交于 2020-01-16 04:32:10
问题 PROBLEM SOLVED. I'm trying to get an person's books, but there are more than one book in my book table since there are different editions of a book. When I list all books of a person, I shouldn't list duplicates. Here's what I've done so far Person Model public function books() { return $this-

Define Laravel Eloquent relations between 3 models in a messaging system

谁都会走 提交于 2020-01-16 00:47:33
问题 I'm trying to create multi-participant messaging system. Here's the database design I'v found here: Messaging system database schema Conversation ------------ id Messages -------- id conversation_id from_id subject message from_timestamp Participants ------------ conversation_id user_id last_read