Resource controller using DocBlock annotations

Now, to illustrate the use of Laravel's DocBlock annotations, we will examine the steps.

First, we will create the accommodations controller as usual:

$ php artisan make:controller AccommodationsController

Next, we will add the accommodations controller to the list of the annotation service provider's routes to scan:

protected $scanRoutes = [
    'AppHttpControllersHomeController',
    'AppHttpControllersAccommodationsController'
];

Now, we will add the DocBlock annotation to the controller. In this case, we will instruct the parser to use this controller as a resource controller for the accommodations route. The code to be added is as follows:

/**
* @Resource("/accommodations")
*/

Since the whole controller will be turned into a resource, the DocBlock annotation should be inserted before the class definition. The AccommodationsController class should now be as follows:

<?php namespace MyCompanyHttpControllers;

use IlluminateSupportFacadesResponse;
use MyCompanyHttpRequests;
use MyCompanyHttpControllersController;
use MyCompanyAccommodation;
use IlluminateHttpRequest;

/**
* @Resource("/accommodations")
*/
class AccommodationsController extends Controller {

    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index(Accommodation $accommodation)
    {
        return $accommodation->paginate();
    }

Note

Note that double quotes are required here:

@Resource("/accommodations")

The following syntax, using single quotes, would not be correct and will not function:

@Resource('/accommodations')
..................Content has been hidden....................

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