diff --git a/readme.md b/readme.md index 06f035b..1f32c16 100755 --- a/readme.md +++ b/readme.md @@ -61,6 +61,13 @@ class AnnotationsServiceProvider extends ServiceProvider { */ protected $scanModels = []; + /** + * The namespace to scan for models in. + * + * @var string + */ + protected $scanModelsInNamespace = null; + /** * Determines if we will auto-scan in the local environment. * @@ -148,6 +155,17 @@ Add models to the `protected $scanModels` array to scan for model annotations. ]; ``` +Or scan your entire models namespace: + +```php + /** + * The namespace to scan for models in. + * + * @var string + */ + protected $scanModelsInNamespace = 'App\Models'; +``` + Alternatively, you can set `protected $scanEverything` to `true` to automatically scan all classes within your application's namespace. *Note:* This may increase the time required to execute the scanners, depending on the size of your application. Scanning your event handlers, controllers, and models can be done manually by using `php artisan event:scan`, `php artisan route:scan`, or `php artisan model:scan` respectively. In the local environment, you can scan them automatically by setting `protected $scanWhenLocal = true`. @@ -529,4 +547,4 @@ class Auth extends Annotation { } } -``` \ No newline at end of file +``` diff --git a/src/AnnotationsServiceProvider.php b/src/AnnotationsServiceProvider.php index a0f8ba8..42a4d3d 100644 --- a/src/AnnotationsServiceProvider.php +++ b/src/AnnotationsServiceProvider.php @@ -56,6 +56,13 @@ class AnnotationsServiceProvider extends ServiceProvider */ protected $scanModels = []; + /** + * The namespace to scan for models in. + * + * @var string + */ + protected $scanModelsInNamespace = null; + /** * Determines if we will auto-scan in the local environment. * @@ -492,6 +499,10 @@ public function modelScans() return $this->getAllClasses(); } + if ($this->scanModelsInNamespace) { + return $this->getClassesFromNamespace($this->scanModelsInNamespace); + } + return $this->scanModels; }