1. Route::get('list', [AppHttpControllersDriverDocumentController::class,'list']);
2. Route::get('list', ['DriverDocumentController@list']);
What is the faster way to load callback from class in laravel route ?
I am writting REST API. I need high performance solution
2
Answers
Both approaches are the same in performance. The Laravel documentation recommends defining your routes in an array format and using action verbs. (
index
instead oflist
)The answer is: it does not matter(*). You should cache things as part of your build script (
php artisan config:cache
,php artisan view:cache
andphp artisan route:cache
).When you cache the routes, a file is created, in
bootstrap/cache/routes-v7.php
if I’m not mistaken. When the routes are cached, yourroutes/web.php
androutes/api.php
files will simply be ignored.(*) you should use the newer syntax still.