Skip to content
This repository has been archived by the owner on Sep 22, 2024. It is now read-only.

Commit

Permalink
Only return the class if it exists
Browse files Browse the repository at this point in the history
  • Loading branch information
pactode committed May 23, 2019
1 parent b20cc6f commit 3de6a32
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Support/ResourceResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ public function resolve(string $model): ?string
throw ResourceNotFoundException::for($resourceClass);
}

return $resourceClass;
return class_exists($resourceClass) ? $resourceClass : null;
}
}
8 changes: 8 additions & 0 deletions tests/Support/ResourceResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,12 @@ public function it_resolves_with_suffix_enabled()

$this->assertEquals(ProductResource::class, $resourceClass);
}

/** @test */
public function it_returns_null_if_the_class_does_not_exist()
{
$resourceClass = $this->resolver->resolve('App\\Models\\Invalid');

$this->assertNull($resourceClass);
}
}

0 comments on commit 3de6a32

Please sign in to comment.