Automatic scanning

If a developer has to execute the Artisan route scan command as the controllers are being built, the effort to do this could become tedious. As a convenience to the developer, there is way to have Laravel automatically scan the controllers in the scanRoutes array on every request to the framework while in the development mode.

In the AnnotationsServiceProvider.php file, set the scanWhenLocal attribute to true.

The same is true for $scanControllers and $scanEverything; these two Boolean flags allow the framework to automatically scan the AppHttpControllers directory, and any class that is namespaced, respectively.

It is imperative to remember that this should only be used during development and on a development machine, since it will add unnecessary overhead to the request cycle. An example of how the attributes are set to true is shown in the following code:

<?php namespace AppProviders;

use CollectiveAnnotationsAnnotationsServiceProvider as ServiceProvider;

class AnnotationsServiceProvider extends ServiceProvider {

    /**
     * The classes to scan for event annotations.
     *
     * @var array
     */
    protected $scanEvents = [];
    
    …

    /**
     * Determines if we will auto-scan in the local environment.
     *
     * @var bool
     */
    protected $scanWhenLocal = true;

    /**
     * Determines whether or not to automatically scan the controllers
     * directory (AppHttpControllers) for routes
     *
     * @var bool
     */
    protected $scanControllers = true;

    /**
     * Determines whether or not to automatically scan all namespaced
     * classes for event, route, and model annotations.
     *
     * @var bool
     */
    protected $scanEverything = true;

}

Enabling these options will slow down the framework, but allow flexibility in the development phase.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset