Article.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Repositories\Models\CMS;
  3. use App\Repositories\Models\Base\Admin;
  4. use App\Repositories\Models\Base\Resource;
  5. use App\Repositories\Models\Model;
  6. use Prettus\Repository\Contracts\Transformable;
  7. use Prettus\Repository\Traits\TransformableTrait;
  8. /**
  9. * Class Article.
  10. *
  11. * @package namespace App\Repositories\Models\CMS;
  12. */
  13. class Article extends Model implements Transformable
  14. {
  15. use TransformableTrait;
  16. protected $table = 'cms_articles';
  17. /**
  18. * The attributes that are mass assignable.
  19. *
  20. * @var array
  21. */
  22. protected $guarded = [];
  23. protected static function booted()
  24. {
  25. self::language();
  26. }
  27. public function cover_resource()
  28. {
  29. return $this->belongsTo(Resource::class, 'cover', 'id')->select(['path', 'id', 'url']);
  30. }
  31. public function setTagsAttribute($val)
  32. {
  33. $this->attributes['tags'] = '-' . arr2str($val, '-') . '-';
  34. }
  35. public function getTagsAttribute($val)
  36. {
  37. return str2arr(trim($val, '-'), '-');
  38. }
  39. public function category()
  40. {
  41. return $this->belongsTo(Category::class);
  42. }
  43. public function admin()
  44. {
  45. return $this->belongsTo(Admin::class);
  46. }
  47. }