Integrate Pjax in Laravel5 to implement the expansion package of refreshing pages-LaravelPjax
1. Introduction
Pjax is a jQuery plug-in that uses ajax to accelerate the page loading time. the working principle is to get the specified HTML segment only from the server, and then the client updates the local page with the obtained content.
The Laravel Pjax extension package integrates Pjax into Laravel. the implementation principle is to provide a middleware and return the desired response content of Pjax.
2. Installation
Use Composer to install the extension package:
$ composer require spatie/laravel-pjax
Next we need to register middleware in Kernel. php. here we will register it to the web middleware group:
// app/Http/Kernel.phpprotected $middlewareGroups = [ 'web' => [ ... \Spatie\Pjax\Middleware\FilterIfPjax::class, ], ...];
3. use
The middleware provided by this extension package processes the content returned by the server and converts it to the content that the Pjax Plug-In expects from the server.
Here we use the default view file generated by the php artisan make: auth command as an example to demonstrate its usage. First, we modify the route file routes. php:
Route::group(['middleware' => 'web'], function () { Route::get('/', function () { return view('welcome'); }); Route::get('/home', 'HomeController@index'); Route::auth();});
Then we need to modify the default layout file layouts/app. blade. php and add the Pjax settings:
...@ Yield ('content ')