-
-
Notifications
You must be signed in to change notification settings - Fork 311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend the models #275
Comments
me too asking that question |
ideal and cleanest would be to have the possibility of providing custom model classes in config - pretty easy to implement, you just have to go through the codebase. @musonza would you like this functionality? if yes, i might make a PR when i have a bit more time not ideal, may potentially introduce some problems and will not solve every use case Create your own model <?php
namespace Domain\Chat\Models;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Musonza\Chat\Models\Conversation as ChatConversation;
class Conversation extends ChatConversation
{
/**
* Messages in conversation.
*
* @return HasMany
*/
public function messages(): HasMany
{
return $this->hasMany(Message::class, 'conversation_id'); //->with('sender');
}
} Create a trait which points to your own model implementation <?php
namespace Domain\Chat\Traits;
use Domain\Chat\Models\Conversation;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
trait InteractsWithChat
{
/**
* Chat relation.
*
* @return BelongsTo
*/
public function chat(): BelongsTo
{
return $this->belongsTo(Conversation::class, 'conversation_id');
}
} this is just a quick thought, i havent thought much about the consequences, but i needed to add one relation of my own to |
Yep, extending package models - core functionality on my opinion. But solution with traits - dirty. Maybe extending of base Chat:class will be is more flexible |
Best way is to extend the core model and add your own functions like @theimerj suggested. |
Is there a way I can extend the models (like Conversation, Participation etc.)?
The text was updated successfully, but these errors were encountered: