Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

CurrentCompanyScope.php 556B

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