سلام دوستان؛خسته نباشید،
من از مولتی اث استفاده کردم و چند گارد (ادمین،کاربر،مشتری) ایجاد کردم، حالا میخوام بین اینا یه سیستم گفتگو ایجاد کنم، حالا میخواسم نظر دوستان رو در مورد رابطه هاش بپرسم،
چیزی که من نوشتم به این شکل هست که:
هر گارد میتونه چندین گفتگو داشته باشه و هر گفتگو هم میتونه چندین پیام داشته باشه،به این شکل
/
relation of user with sender conversation.
@return MorphOne
/
public function sender()
{
return $this->morphMany(Conversation::class,'senderable');
}
/
relation of user with receiver conversation.
@return MorphOne
/
public function receiver()
{
return $this->morphMany(Conversation::class,'receiverable');
}
/
return relation of user with conversation.
@return MorphOne
/
public function conversations()
{
return $this->sender() ?? $this->receiver();
}
/
relation of conversation with user_type:admin,user,customer
@return MorphTo
/
public function senderable()
{
return $this->morphTo();
}
/
relation of conversation with user_type:admin,user,customer
@return MorphTo
/
public function receiverable()
{
return $this->morphTo();
}
/
relation of conversation with message.
@return HasMany
/
public function messages()
{
return $this->hasMany(Message::class);
}
حالا میخوام بدونم به این شکل بهینه هست؟یا روش بهتری کسی انجام داده،ممنون میشم راهنمایی کنید
@hesammousavi
@ali.bayat
@Alimotreb
@juza66
@milad
@khanzadimahdi
شاید پاسخ شما همینجا باشد
@hesammousavi
اونوقت به این شکل بهتره یه فیلد type تعریف یشه واسه جدا کردنشون؟یا از Acl استفاده بشه؟چون از acl واسه مدیریت استفاده کردم
(ببخشید سوالاتم زیاد شد:))