I’m building a mult-tenant auth system, that each user can belong of “x” companies. In Users Table, there is a field named “companies_id”, that contain the companies IDS that he belongs ( between “,” ), ex: 1,9,25,30. I can List all User Companies through query scopes e Query Builder:
class Company extends Model
{
protected static function boot()
{
parent::boot();
static::addGlobalScope(new CompanyScope());
}
class CompanyScope implements Scope
{
public function apply(Builder $builder, Model $model)
{
$companies_id = auth()->user()->companies_id;
$pieces = explode(",", $ companies _id);
foreach ($pieces as $k){
$builder->orwhere('companies_id', $k);
}
}
In INDEX page is OK, but, if I need show only ONE Company that a user belongs I can’t. I Have a Method in Company Controller : Show($id){ }.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire