You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
779 B

3 years ago
  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Model;
  4. class Reaction extends Model
  5. {
  6. protected $primaryKey = 'message_mid';
  7. protected $casts = [
  8. 'created_at' => 'datetime:Y-m-d H:i:s',
  9. 'updated_at' => 'datetime:Y-m-d H:i:s',
  10. ];
  11. public function message()
  12. {
  13. return $this->belongsTo(Message::class);
  14. }
  15. public function contact()
  16. {
  17. return $this->hasOne(Contact::class, 'id', 'jidfrom');
  18. }
  19. public function getTruenameAttribute()
  20. {
  21. if ($this->contact) {
  22. return $this->contact->truename;
  23. }
  24. if (str_contains($this->jidfrom, '@')) {
  25. return explodeJid($this->jidfrom)['username'];
  26. } else {
  27. return $this->jidfrom;
  28. }
  29. }
  30. }