StocksNew/app/Models/Scopes/CreatedByScope.php

26 lines
675 B
PHP
Raw Permalink Normal View History

2024-08-27 12:03:06 +00:00
<?php
namespace App\Models\Scopes;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Scope;
class CreatedByScope implements Scope
{
/**
* Apply the scope to a given Eloquent query builder.
*/
public function apply(Builder $builder, Model $model): void
{
if (auth()->user()->hasRole('admin')) {
// $builder->where('dftqcoffice_id', auth()->user()->dftqcoffice_id);
}
if (auth()->user()->hasRole('employee')) {
$user = \Auth::user();
$builder->where($model->getTable() . '.employee_id', $user->employee_id);
}
}
}