Integrate Pjax in Laravel5 to implement the expansion package of refreshing pages-LaravelPjax

Source: Internet
Author: User
Tags cloudflare
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 ')

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.