Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Bouncer.php
Original file line number Diff line number Diff line change
Expand Up @@ -524,9 +524,9 @@ public function tables(array $map)
/**
* Get the model scoping instance.
*
* @return mixed
* @return Scope
*/
public function scope(?Scope $scope = null)
public function scope(?Scope $scope = null): Scope
{
return Models::scope($scope);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Database/Models.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ public static function table($table)
/**
* Get or set the model scoping instance.
*
* @return mixed
* @return ScopeContract
*/
public static function scope(?ScopeContract $scope = null)
public static function scope(?ScopeContract $scope = null): ScopeContract
{
if (! is_null($scope)) {
return static::$scope = $scope;
Expand Down
2 changes: 2 additions & 0 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public function create()

$bouncer = (new Bouncer($guard))->setGate($gate);

$bouncer->scope()->remove();

if ($this->registerAtGate) {
$guard->registerAt($gate);
}
Expand Down
12 changes: 12 additions & 0 deletions tests/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Container\Container;
use PHPUnit\Framework\Attributes\Test;
use Silber\Bouncer\Bouncer;
use Silber\Bouncer\Database\Models;
use Workbench\App\Models\User;

class FactoryTest extends BaseTestCase
Expand Down Expand Up @@ -58,4 +59,15 @@ public function can_build_up_bouncer_with_the_given_gate()
$this->assertTrue($bouncer->can('create-bouncers'));
$this->assertTrue($bouncer->cannot('delete-bouncers'));
}

#[Test]
public function can_create_bouncer_instance_and_reset_scope()
{
Models::scope()->to(1);
$this->assertNotNull(Models::scope()->get());

$bouncer = Bouncer::create();

$this->assertNull(Models::scope()->get());
}
}