Story.php 968 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace App;
  3. use Auth;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Pixelfed\Snowflake\HasSnowflakePrimary;
  6. class Story extends Model
  7. {
  8. use HasSnowflakePrimary;
  9. public const MAX_PER_DAY = 20;
  10. /**
  11. * Indicates if the IDs are auto-incrementing.
  12. *
  13. * @var bool
  14. */
  15. public $incrementing = false;
  16. /**
  17. * The attributes that should be mutated to dates.
  18. *
  19. * @var array
  20. */
  21. protected $dates = ['published_at', 'expires_at'];
  22. protected $fillable = ['profile_id'];
  23. protected $visible = ['id'];
  24. protected $hidden = ['json'];
  25. public function profile()
  26. {
  27. return $this->belongsTo(Profile::class);
  28. }
  29. public function views()
  30. {
  31. return $this->hasMany(StoryView::class);
  32. }
  33. public function seen($pid = false)
  34. {
  35. return StoryView::whereStoryId($this->id)
  36. ->whereProfileId(Auth::user()->profile->id)
  37. ->exists();
  38. }
  39. public function permalink()
  40. {
  41. return url("/story/$this->id");
  42. }
  43. }