page-cache icon indicating copy to clipboard operation
page-cache copied to clipboard

Installation instructions on Laravel 10

Open RasmusLindstrom opened this issue 2 years ago • 2 comments

I tried to install this on Laravel 10, but the instructions don't match

  1. When I want to run this on specific pages, the instructions say to first open "app/Http/Kernel.php" and then "...you should instead add a new mapping to the routeMiddleware array", but there's no such array in that Kernel-file. I can find one in another Kernel.php, where there's an empty array. Should it be added there instead?

  2. Web.php seems to have a different format in Laravel 10 than last time I played around with Laravel, now a route in "web.php" looks like this: Route::get('/', function () { return view('index'); });

According to the docs, the way to do this would be: Route::middleware('page-cache')->get('/', 'PostController@index'); But that is not working. [Perhaps the issue here is that I implemented the middleware incorrectly in 1)]

Thanks!

RasmusLindstrom avatar Feb 20 '23 07:02 RasmusLindstrom

In Laravel 10, routeMiddleware has been renamed to middlewareAliases.

Thanks for reminding me to update the docs: https://github.com/JosephSilber/page-cache/commit/3893f3943a940c87ad668de4b05499198251f31d

JosephSilber avatar Feb 20 '23 18:02 JosephSilber

Web.php seems to have a different format in Laravel 10 than last time I played around with Laravel

Both of these syntaxes are valid:

// This uses an inline function to handle the route:
Route::middleware('page-cache')->get('/', function () {
    return view('index');
});

// This uses a controller method to handle the route:
Route::middleware('page-cache')->get('/', 'PostController@index');

See the Laravel documentation for more details: https://laravel.com/docs/10.x/routing#basic-routing

JosephSilber avatar Feb 20 '23 18:02 JosephSilber