Like.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. /**
  9. * The attributes that should be mutated to dates.
  10. *
  11. * @var array
  12. */
  13. protected $dates = ['deleted_at'];
  14. protected $fillable = ['profile_id', 'status_id'];
  15. public function actor()
  16. {
  17. return $this->belongsTo(Profile::class, 'profile_id', 'id');
  18. }
  19. public function status()
  20. {
  21. return $this->belongsTo(Status::class);
  22. }
  23. public function toText($type = 'post')
  24. {
  25. $actorName = $this->actor->username;
  26. $msg = $type == 'post' ? __('notification.likedPhoto') : __('notification.likedComment');
  27. return "{$actorName} ".$msg;
  28. }
  29. public function toHtml($type = 'post')
  30. {
  31. $actorName = $this->actor->username;
  32. $actorUrl = $this->actor->url();
  33. $msg = $type == 'post' ? __('notification.likedPhoto') : __('notification.likedComment');
  34. return "<a href='{$actorUrl}' class='profile-link'>{$actorName}</a> ".$msg;
  35. }
  36. }