Owner.php 1004 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Database\Eloquent\SoftDeletes;
  5. use Illuminate\Support\Facades\Auth;
  6. /**
  7. * @method static orderBy(string $string, string $string1)
  8. */use App\Traits\ModelTimeFormat;
  9. class Owner extends Model
  10. {
  11. use ModelTimeFormat;
  12. use SoftDeletes;
  13. public $fillable = ['name','code','checking_count'];
  14. public static function filterAuthorities(){
  15. $user=Auth::user();
  16. if(!$user){
  17. return (new static)->newQuery()->where('id','0');
  18. }
  19. $ownerIds=$user->getPermittingOwnerIdsAttribute();
  20. return (new static)->newQuery()->whereIn('id',$ownerIds);
  21. }
  22. public function getIncreasedCheckingCount(){
  23. $this['checking_count']=$this['checking_count']+1;
  24. $this->update();
  25. return $this['checking_count'];
  26. }
  27. public function paperBoxes()
  28. {
  29. return $this->belongsToMany('\App\PaperBox', 'owner_paper_box', 'owner_id', 'paper_box_id');
  30. }
  31. }