2
I’m calling the class TenantScope
in the model Cliente
and makes a mistake
Tenantscope.php
namespace App\Scopes\Tenant;
use App\Tenant\ManagerTenant;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Scope;
use Illuminate\Database\Query\Builder;
class TenantScope implements Scope
{
public function apply(Builder $builder, Model $model)
{
$tenant = new ManagerTenant;
$tenant->getTenantIdentify();
$builder->where('tenant_id', $tenant)->get();
}
}
Error:
Whoops\Exception\ErrorException : Declaration of App\Scopes\Tenant\TenantScope::apply(Illuminate\Database\Query\Builder $builder, Illuminate\Database\Eloquent\Model $model) must be compatible with Illuminate\Database\Eloquent\Scope::apply(Illuminate\Database\Eloquent\Builder $builder, Illuminate\Database\Eloquent\Model $model)
Client.php //Model
<?php
namespace App\Models;
use app\Scopes\Tenant\TenantScope;
use Illuminate\Database\Eloquent\Model;
class Cliente extends Model
{
protected $fillable = [
'nome',
];
´ public static function boot()
{
parent::boot();
static::addGlobalScope(new TenantScope);
}
}
Perfect, thank you very much
– André Cabral