lnch/laravel-pjax

A Laravel Facade to create blocks of content that will reload on any links

This package's canonical repository appears to be gone and the package has been frozen as a result.

1.1.7 2017-09-28 15:27 UTC

This package is auto-updated.

Last update: 2019-06-23 20:26:01 UTC


README

Pjax is jquery plugin that leverages ajax to speed up the loading time of your pages. It works by only fetching specific html fragments from the server, and client-side updating only certain parts of the page.

The package provides a middleware that can return the response that the jquery plugin expects. It also provides a helpful Facade to help with specifying blocks of content that should be handled by Pjax.

You're free to use this package, as it's MIT-licensed), but if it does make it to your production environment, we'd love to hear from you. Send us an email at usage@lnch.co.uk and let us know and you could get onto our website.

Installation

You can install the package via composer:

$ composer require lnch/laravel-pjax

To filter the requests, you must add \Lnch\Pjax\Middleware\FilterRequestsForPjax middleware to the kernel.

// app/Http/Kernel.php

...
protected $middleware = [
    ...
    \Lnch\Pjax\Middleware\FilterRequestsForPjax::class,
];

To allow the Facade to work, you need to add the ServiceProvider to the config\app.php file

'providers' => [
    ...
    \Lnch\Pjax\PjaxServiceProvider::class
]

And to create the alias for the Facade, add it to the aliases array in config\app.php. Feel free to use a different alias here if you don't want to use Pjax

'aliases' => [
    ...
    'Pjax' => Lnch\Pjax\PjaxFacade::class,
]

You will also need to publish the vendor assets so that you can link the JS files in your projects

$ php artisan vendor:publish --tag=laravel-pjax

Usage

The provided middleware provides the behaviour that the pjax plugin expects of the server:

An X-PJAX request header is set to differentiate a pjax request from normal XHR requests. In this case, if the request is pjax, we skip the layout html and just render the inner contents of the container.

Credits

The middleware in this package was originally written by Jeffrey Way for the Laracasts lesson on pjax. His original code can be found in this repo on GitHub.

License

The MIT License (MIT). Please see License File for more information.