Like.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Database\Eloquent\SoftDeletes;
  5. class Like extends Model
  6. {
  7. use SoftDeletes;
  8. const MAX_PER_DAY = 200;
  9. /**
  10. * The attributes that should be mutated to dates.
  11. *
  12. * @var array
  13. */
  14. protected $dates = ['deleted_at'];
  15. protected $fillable = ['profile_id', 'status_id'];
  16. public function actor()
  17. {
  18. return $this->belongsTo(Profile::class, 'profile_id', 'id');
  19. }
  20. public function status()
  21. {
  22. return $this->belongsTo(Status::class);
  23. }
  24. public function toText($type = 'post')
  25. {
  26. $actorName = $this->actor->username;
  27. $msg = $type == 'post' ? __('notification.likedPhoto') : __('notification.likedComment');
  28. return "{$actorName} ".$msg;
  29. }
  30. public function toHtml($type = 'post')
  31. {
  32. $actorName = $this->actor->username;
  33. $actorUrl = $this->actor->url();
  34. $msg = $type == 'post' ? __('notification.likedPhoto') : __('notification.likedComment');
  35. return "<a href='{$actorUrl}' class='profile-link'>{$actorName}</a> ".$msg;
  36. }
  37. }