Article.php 497 B

123456789101112131415161718192021
  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Support\Facades\Auth;
  5. class Article extends Model
  6. {
  7. protected $fillable = ['user_id', 'body', 'status'];
  8. public function like()
  9. {
  10. return Like::where('user_id', Auth::id())->where('post_id', $this->id)->where('type', 'article')->first();
  11. }
  12. public function likes_count()
  13. {
  14. return Like::where('post_id', $this->id)->where('type', 'article')->where('status', 1)->count();
  15. }
  16. }