Article.php 660 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: zilongs
  5. * Date: 20-10-5
  6. * Time: 下午3:37
  7. */
  8. namespace App\Models;
  9. class Article extends BaseModel
  10. {
  11. protected $appends = ['is_collect'];
  12. protected $table = 'articles';
  13. public static $_post_type = [
  14. 1=>'健康科普',
  15. 2=>'疫苗科普'
  16. ];
  17. public function getIsCollectAttribute()
  18. {
  19. if (!empty(request()->header('token'))) {
  20. $user = User::getUserByToken();
  21. if (Collection::where('user_id', $user['id'])->where('article_id', $this->id)->exists()) {
  22. return 1;
  23. }
  24. }
  25. return 0;
  26. }
  27. }