Skip to content

Instantly share code, notes, and snippets.

@vinicius73
Created March 5, 2016 06:26
Show Gist options
  • Save vinicius73/df742c7e61b62f4fc0a7 to your computer and use it in GitHub Desktop.
Save vinicius73/df742c7e61b62f4fc0a7 to your computer and use it in GitHub Desktop.
Tenant RegularTenantRepository
<?php
namespace App\Domains\Tenants\Repositories\Traits;
use App\Domains\Tenants\Tenant;
trait RegularTenantRepository
{
/**
* @var Tenant
*/
protected $tenant;
public function __construct(Tenant $tenant)
{
$this->tenant = $tenant;
}
/**
* @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder
*/
public function newQuery()
{
$query = parent::newQuery();
return $query->where('tenant_id', $this->tenant->id);
}
/**
* @param array $data
*
* @return \Illuminate\Database\Eloquent\Model
*/
public function factory(array $data = [])
{
$model = parent::factory($data);
$model->tenant_id = $this->tenant->id;
return $model;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment