pedroborges
5 years ago
1400
152
General

Route annotation in Laravel 5

Posted 5 years ago by pedroborges

Laravel 5 now includes route annotation. Which means now you can have a controller like this:

<?php namespace App\Http\Controllers;

use Illuminate\Routing\Controller;

/**
 * @Resource("foobar/photos", only={"index", "update"}, names={"index": "index.name"})
 * @Controller(domain="{id}.account.com")
 * @Before("auth")
 * @Before("csrf", on={"post", "put", "delete"})
 * @Where({"id": "regex"})
 */
class BasicController extends Controller {

 /**
  * @Before("inline")
  * @return Response
  */
 public function index() {}

 /**
  * @Before("inline")
  * @After("inline")
  * @return Response
  */
 public function update($id) {}

 /**
  * @Put("/more/{id}", after="log")
  */
 public function doMore($id) {}

}

Then you have to run php artisan route:scan and Laravel will cache all annotated routes in storage/framework/routes.scanned.php

What do you guys think of this feature?

Please sign in or create an account to participate in this conversation.