From e4d2516d40c8bae014c08daaf5b7abe415b3ee8f Mon Sep 17 00:00:00 2001 From: myckhel Date: Fri, 15 Oct 2021 23:32:21 +0100 Subject: [PATCH] renamed `withTrashed` to `withAll` --- src/Http/Controllers/ConversationController.php | 3 ++- src/Http/Controllers/MessageController.php | 2 +- src/Models/ChatEvent.php | 10 ++++------ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Http/Controllers/ConversationController.php b/src/Http/Controllers/ConversationController.php index 43fb0b3..5a4d311 100644 --- a/src/Http/Controllers/ConversationController.php +++ b/src/Http/Controllers/ConversationController.php @@ -36,13 +36,14 @@ public function index(PaginableRequest $request) ]) ->orderByDesc('latest_message_at') ->with([ + // 'chatEvents' => fn ($q) => $q->groupBy('chat_events.id', 'chat_events.maker_type', 'chat_events.maker_id', 'chat_events.made_type', 'chat_events.made_id', 'chat_events.all', 'chat_events.created_at', 'chat_events.updated_at'), 'delivery' => fn ($q) => $queryEvent($q)->where('maker_id', '!=', $user->id), 'read' => fn ($q) => $queryEvent($q)->where('maker_id', '!=', $user->id), 'trashed' => $queryEvent, 'last_message' => fn ($q) => $q->select(['id','user_id','message','conversation_id', 'created_at']) ->with([ // 'latestMedia' => fn ($q) => $q->select('id', 'model_type', 'model_id', 'name'), - 'trashed' => fn ($q) => $q->withTrashed($user) + 'trashed' => fn ($q) => $q->withAll($user) ]), 'participant' => fn ($q) => $q->select('id', 'user_id', 'conversation_id')->where('user_id', '!=', $user->id), 'participant.user' => fn ($q) => $q,//->withUrls(['avatar']), diff --git a/src/Http/Controllers/MessageController.php b/src/Http/Controllers/MessageController.php index f915293..4de01b1 100644 --- a/src/Http/Controllers/MessageController.php +++ b/src/Http/Controllers/MessageController.php @@ -44,7 +44,7 @@ public function index(PaginableRequest $request) $reply = []; $with = [ 'reply', - 'trashed' => fn ($q) => $q->withTrashed($user), + 'trashed' => fn ($q) => $q->withAll($user), 'sender', ]; diff --git a/src/Models/ChatEvent.php b/src/Models/ChatEvent.php index 74b9d9a..253f8a8 100644 --- a/src/Models/ChatEvent.php +++ b/src/Models/ChatEvent.php @@ -21,8 +21,8 @@ protected static function newFactory(){ return ChatEventFactory::new(); } - function scopeWithTrashed($q, ChatEventMaker $user) { - $q->select('id', 'maker_id', 'maker_type', 'made_id', 'made_type', 'all')->whereMakerId($user->id)->orWhere('all', true); + function scopeWithAll($q, ChatEventMaker $user) { + $q->select('*')->whereMakerId($user->id)->orWhere('all', true); } function scopeNotMessanger($q, ChatEventMaker|int $user) { @@ -30,13 +30,11 @@ function scopeNotMessanger($q, ChatEventMaker|int $user) { } function message(): BelongsTo { - $message = self::config('models.message'); - return $this->belongsTo($message, 'made_id')->whereMadeType($message); + return $this->belongsTo(self::config('models.message'), 'made_id'); } function conversation(): BelongsTo { - $conversation = self::config('models.conversation'); - return $this->belongsTo($conversation, 'made_id')->whereMadeType($conversation); + return $this->belongsTo(self::config('models.conversation'), 'made_id'); } function maker(): MorphTo{