Route annotation in Laravel 5

Posted 4 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.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.