mardi 31 décembre 2019

Laravel correct way to name and define routes?

Example 1:

Route::get('/', 'API\PostController@index')->name(‘post.index’);

Example 2:

Route::get('/', [PostController::class, 'index'])->name(‘post.index’);

In this example we need to use the following use statement at the top of the route file:

use App\Http\Controllers\API\PostController;

The second example makes it easy to navigate across the controllers from the route file with a cmd + click but compared to better performance which is the best ?

Is it must to define named routes when using the laravel only as a API, can it add more overhead to overall performance ?



via Chebli Mohamed

1 commentaire: