Owner.php 937 B

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