Laravel 5.7 Callable Action URLs

Laravel 5.7 Callable Action URLs

A new callable-like syntax for action URLs is coming to Laravel 5.7 thanks to Sebastian De Deyne! You might also hear this feature called “tuple notation” or a “callable array syntax” for URL generation actions.

Here’s how it works starting in 5.7:

<?php

$url = action([PostsController::class, 'index']);

Currently (as of Laravel 5.6) the action helper only supports the following style that you’re probably already familiar with:

<?php

$url = action('UserController@profile', ['id' => 1]);

One benefit of the new callable array syntax format is the ability to navigate to directly to the controller if you use a text editor or IDE that supports code navigation.

You can find it in the upcoming documentation for URL Generation, and if you’re interested in the code changes made to support this feature, you can check out the 5.7 Tuple notation for UrlGenerator actions pull request.


Filed in: Laravel 5.7


Newsletter

Join the weekly newsletter and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Senior Laravel Engineer
Remote okay (must already live in USA)
Hawthorne Effect
Senior Software Engineer (Remote - Contract)
Remote
Koodi Systems
PHP Developer
Pittsburgh / Remote
Sequoia Waste Solutions
Software Developer
Eindhoven
Simac IDS
Application Developer Level II (CakePHP / MySql / Vue.js)
Lancaster, PA
Harbor Compliance
FULL STACK LARAVEL DEVELOPER
LONDON - WEST END
AMPERSAND HEATLH
Mid/Senior Laravel Developer - U.S. Only
Kenner, Louisiana
Profit Miner Technologies