Created
March 5, 2016 06:26
-
-
Save vinicius73/df742c7e61b62f4fc0a7 to your computer and use it in GitHub Desktop.
Tenant RegularTenantRepository
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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