您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

CurrentCompanyScope.php 471B

12345678910111213141516171819
  1. <?php
  2. namespace App\Scopes;
  3. use Illuminate\Database\Eloquent\{Builder, Model, Scope};
  4. use Illuminate\Support\Facades\Auth;
  5. class CurrentCompanyScope implements Scope
  6. {
  7. /**
  8. * Apply the scope to a given Eloquent query builder.
  9. */
  10. public function apply(Builder $builder, Model $model): void
  11. {
  12. if (Auth::check() && Auth::user()->currentCompany) {
  13. $builder->where('company_id', Auth::user()->currentCompany->id);
  14. }
  15. }
  16. }