Post.php 674 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019/6/5
  6. * Time: 16:24
  7. */
  8. namespace App\Models;
  9. use Illuminate\Database\Eloquent\Model;
  10. use Illuminate\Database\Eloquent\SoftDeletes;
  11. class Post extends Model
  12. {
  13. //
  14. use SoftDeletes;
  15. protected $table = 'post';
  16. protected $guarded = [];
  17. public function imgs()
  18. {
  19. return $this->hasMany('App\Models\PostImgs', 'post_id', 'id');
  20. }
  21. public function data()
  22. {
  23. return $this->hasOne('App\Models\PostData', 'post_id', 'id');
  24. }
  25. public function topic()
  26. {
  27. return Topic::whereIn('id', explode(',', $this->topic_ids))->pluck('name', 'id');
  28. }
  29. }