26 lines
675 B
PHP
26 lines
675 B
PHP
|
<?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);
|
||
|
}
|
||
|
}
|
||
|
}
|