Skip to content

Commit

Permalink
Merge pull request #7 from arthurkirkosa/don-t-run-in-console
Browse files Browse the repository at this point in the history
Don't apply scope in console env (tinker)
  • Loading branch information
binaryk authored Dec 8, 2020
2 parents 2c9c222 + b16f8b5 commit 44af0c8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Models/BelongsToTenant.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace BinarCode\Tenantable\Models;

use Illuminate\Support\Facades\App;

/**
* Trait BelongsToTenant
* @package BinarCode\Tenantable\Models
Expand All @@ -18,7 +20,9 @@ public function tenant()

public static function bootBelongsToTenant()
{
static::addGlobalScope(new TenantScope);
if (! App::runningInConsole()) {
static::addGlobalScope(new TenantScope);
}

static::creating(function ($model) {
if (! $model->getAttribute(BelongsToTenant::$tenantIdColumn) && ! $model->relationLoaded('tenant')) {
Expand Down

0 comments on commit 44af0c8

Please sign in to comment.