StocksNew/app/Models/Scopes/CreatedByScope.php
Sampanna Rimal 53c0140f58 first commit
2024-08-27 17:48:06 +05:45

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);
}
}
}