PHPackages                             randomwhitetrash/laravel-grid - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. randomwhitetrash/laravel-grid

ActiveLibrary[Templating &amp; Views](/categories/templating)

randomwhitetrash/laravel-grid
=============================

A grid view for laravel, inspired by the yii2 grid widget. Based on the randomwhitetrash/laravel-grid package.

v4.0.4(1y ago)083MITPHP

Since Feb 15Pushed 1y agoCompare

[ Source](https://github.com/RandomWhiteTrash/laravel-grid)[ Packagist](https://packagist.org/packages/randomwhitetrash/laravel-grid)[ Docs](https://github.com/RandomWhiteTrash/laravel-grid)[ RSS](/packages/randomwhitetrash-laravel-grid/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (13)Versions (50)Used By (0)

Laravel grid
============

[](#laravel-grid)

Live demo: [here](http://laravel-grid.herokuapp.com/)

[![Build Status](https://camo.githubusercontent.com/5120a46b6a3922eb8d82b8a8d4db34de48d6e77014b0ff0ce9becd9b1a5a695f/68747470733a2f2f7472617669732d63692e6f72672f72616e646f6d776869746574726173682f6c61726176656c2d677269642e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/randomwhitetrash/laravel-grid)[![Latest Stable Version](https://camo.githubusercontent.com/0b47e8608b7c5c42a1f5f39cfdf7fd6928c8df8a62b4e8c7dbe52da5ab4d4949/68747470733a2f2f706f7365722e707567782e6f72672f72616e646f6d776869746574726173682f6c61726176656c2d677269642f762f737461626c65)](https://packagist.org/packages/randomwhitetrash/laravel-grid)[![Latest Unstable Version](https://camo.githubusercontent.com/5a4e09a64f250c805ccf6dd1ccea533c185c5b3aa49b2d5489f354312a1b651b/68747470733a2f2f706f7365722e707567782e6f72672f72616e646f6d776869746574726173682f6c61726176656c2d677269642f762f756e737461626c65)](https://packagist.org/packages/randomwhitetrash/laravel-grid)[![Total Downloads](https://camo.githubusercontent.com/963569544ea08d8442946179f9280b9aa4463ee4e61737a2ce6600b4fba6d993/68747470733a2f2f706f7365722e707567782e6f72672f72616e646f6d776869746574726173682f6c61726176656c2d677269642f646f776e6c6f616473)](https://packagist.org/packages/randomwhitetrash/laravel-grid)

This package allows rendering of data via a tabular format (grid). The grid uses bootstrap classes to style the `table` elements. Icons used are from `font-awesome`, and most of the functionality is insipred by the yii2's framework's gridview widget.

Requirements
------------

[](#requirements)

- Laravel 10+
- Bootstrap 4 (for the styling)
- Font awesome (for icons)
- Jquery (required by bootstrap and the package's javascript)
- Jquery pjax (quickly view data without having to reload the page). Note that you'll need to [create the middleware on your own](https://gist.github.com/JeffreyWay/8526696b6f29201c4e33)
- [Date picker](https://github.com/dangrossman/bootstrap-daterangepicker.git) (optional - for the single date &amp; date range filters)

> **Note that from version 2.0.2 onwards, you'll need the package [barryvdh/laravel-dompdf](https://github.com/barryvdh/laravel-dompdf) to export data from the grid as PDF**

Getting started
===============

[](#getting-started)

Install
-------

[](#install)

The package is available on packagist. Just run;

```
composer install RandomWhiteTrash/laravel-grid "^4.0"
```

If you can't wait for a release inorder to try any fixes, or the latest features, just run;

```
composer install RandomWhiteTrash/laravel-grid "4.0.x-dev"
```

Publish assets
--------------

[](#publish-assets)

The grid comes with a config file, CSS assets, JS assets and view files. The command below should allow you to publish them.

```
php artisan vendor:publish --provider="RandomWhiteTrash\Grid\Providers\GridServiceProvider"
```

> You can also choose to publish the assets and views separately by passing the `--tag` argument to the command. For the argument values, try `assets`, `views`, `config` for js|css assets, views and config respectively.

Add/Customize your layout
-------------------------

[](#addcustomize-your-layout)

Be sure to also include the necessary javascript and css assets on your layout. An example layout is as shown below;

```

    My application

            My appliation

        @yield('content')

@include('randomwhitetrash::modal.container')

    // send csrf token (see https://laravel.com/docs/5.6/csrf#csrf-x-csrf-token) - this is required
    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });

    // for the progress bar (required for progress bar functionality)
    $(document).on('pjax:start', function () {
        NProgress.start();
    });
    $(document).on('pjax:end', function () {
        NProgress.done();
    });

@stack('grid_js')

```

Creating grids
--------------

[](#creating-grids)

A laravel command is available to make it easy to create grids. It's usage is as shown below;

```
php artisan make:grid --model="{modelClass}"
```

Just make sure you replace `{modelClass}` with your actual `eloquent` model class. E.g

```
php artisan make:grid --model="App\User"
```

Once this is run, a grid will be generated. Default namespace for grid generation is `App\Grids`. Once the generation of the grid is done, you can add add it in your controller like this;

```
class UsersController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @param UsersGridInterface $usersGrid
     * @param Request $request
     * @return \Illuminate\Http\Response
     */
    public function index(UsersGridInterface $usersGrid, Request $request)
    {
        // the 'query' argument needs to be an instance of the eloquent query builder
        // you can load relationships at this point
        return $usersGrid
                    ->create(['query' => User::query(), 'request' => $request])
                    ->renderOn('welcome'); // render the grid on the welcome view
    }
}
```

Just make sure that you do not call `->get()` on the query.

If you inject the interface on the controller, just make sure that you add a binding to the service provider. Like this;

```
     /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->bind(UsersGridInterface::class, UsersGrid::class);
    }
```

Otherwise, you can also instantiate the grid class like any other class then inject any constructor dependencies you might need.

```
    /**
     * Display a listing of the resource.
     *
     * @param Request $request
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $user = $request->user();
        return (new UsersGrid(['user' => $user])) // you can then use it as $this->user within the class. It's set implicitly using the __set() call
                    ->create(['query' => User::query(), 'request' => $request])
                    ->renderOn('welcome');
    }
```

If you need to pass extra data to the view specified, you just need to pass the data as arguments, just as you do normally on any other laravel controller;

```
    /**
     * Display a listing of the resource.
     *
     * @param Request $request
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $data = 'hello world';

        return (new UsersGrid())
                    ->create(['query' => User::query(), 'request' => $request])
                    ->renderOn('welcome', compact('data'));
    }
```

For eloquent relationships, its basically the same approach. Like this;

```
class UsersController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @param UsersGridInterface $usersGrid
     * @param Request $request
     * @return \Illuminate\Http\Response
     */
    public function index(UsersGridInterface $usersGrid, Request $request)
    {
        // load relationships
        $query = User::with(['posts', 'activities'])
        return $usersGrid
                    ->create(['query' => $query, 'request' => $request])
                    ->renderOn('welcome');
    }
}
```

And once again, just make sure that you do not call `->get()` on the query.

Rendering the grid
------------------

[](#rendering-the-grid)

To display your grid, simply add this to your view. Or any appropriate variable you passed into the `renderOn` method.

```
{!! $grid !!}
```

For a quick demonstration, be sure to check out the demo [here](http://laravel-grid.herokuapp.com/). The demo's source code is also [available on github](https://github.com/randomwhitetrash/laravel-grid-app).

Updating local JS and CSS assets after package updates
------------------------------------------------------

[](#updating-local-js-and-css-assets-after-package-updates)

When the package is updated, it is highly likely that you will also need to update the javascript assets. To do that, run this command below after an update;

```
php artisan vendor:publish --provider="RandomWhiteTrash\Grid\Providers\GridServiceProvider" --tag=assets --force
```

You can also place this command in composer so that it is executed automatically on each update run. Like this;

```
// ... composer config
"post-autoload-dump": [
    "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
    "@php artisan package:discover",
    "@php artisan vendor:publish --provider=\"RandomWhiteTrash\\Grid\\Providers\\GridServiceProvider\" --tag=assets --force"
]
```

Next up
=======

[](#next-up)

[Rendering the grid](docs/rendering.md)

###  Health Score

38

—

LowBetter than 84% of packages

Maintenance44

Moderate activity, may be stable

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 91.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~59 days

Recently: every ~68 days

Total

44

Last Release

471d ago

Major Versions

1.0.16 → 2.0.02018-05-21

2.0.x-dev → 3.02020-01-09

v3.0.11 → v4.0.0-alpha2024-04-16

### Community

Maintainers

![](https://www.gravatar.com/avatar/711a479758b8566e7d496287904419c452ffd30eced51fa783a11100b53e7736?d=identicon)[RandomWhiteTrash](/maintainers/RandomWhiteTrash)

---

Top Contributors

[![leantony](https://avatars.githubusercontent.com/u/7967272?v=4)](https://github.com/leantony "leantony (340 commits)")[![RandomWhiteTrash](https://avatars.githubusercontent.com/u/3501330?v=4)](https://github.com/RandomWhiteTrash "RandomWhiteTrash (32 commits)")

---

Tags

laravelgridbootstrappjaxlaravel10laravel-gridrandom-white-trashrandomwhitetrash

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/randomwhitetrash-laravel-grid/health.svg)

```
[![Health](https://phpackages.com/badges/randomwhitetrash-laravel-grid/health.svg)](https://phpackages.com/packages/randomwhitetrash-laravel-grid)
```

###  Alternatives

[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.5k25.9M106](/packages/laravel-cashier)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k12.1M99](/packages/laravel-pulse)[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k43.5M5.2k](/packages/larastan-larastan)[laravel/passport

Laravel Passport provides OAuth2 server support to Laravel.

3.4k85.0M528](/packages/laravel-passport)[leantony/laravel-grid

A grid view for laravel, inspired by the yii2 grid widget

9060.2k](/packages/leantony-laravel-grid)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
