PHP code example of churakovmike / laravel-grid

1. Go to this page and download the library: Download churakovmike/laravel-grid library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

churakovmike / laravel-grid example snippets


composer 

ChurakovMike\EasyGrid\GridViewServiceProvider::class,       



namespace App\Http\Controllers;

use ChurakovMike\EasyGrid\DataProviders\EloquentDataProvider;

class ExampleController extends Controller
{
    public function example()
    {
        $dataProvider = new EloquentDataProvider(ExampleModel::query());
        return view('example-view', [
            'dataProvider' => $dataProvider,
        ]);
    }
}


{!! easy_grid([
    'dataProvider' => $dataProvider,
    'columns' => [
        'id',
        'name',
        'email',
        'status',
        'created_at',
    ],
]) !!}

{!! easy_grid([
    'dataProvider' => $dataProvider,
    'columns' => [
        'id',
        [
            'label' => 'Users name',
            'attribute' => 'name',
        ],
        [
            'label' => 'Custom label',
            'attribute' => 'id'
        ],
        [
            'label' => 'Example callbacks',
            'value' => function($data) {
                return $data->relatedModel->attribute;
            }
        ],
        'email',
        'status',
        'created_at',
    ],
]) !!}

{!! easy_grid([
    'dataProvider' => $dataProvider,
    'columns' => [
        [
            'label' => 'There are no model attribute',
            'value' => function($data) {
                return 'example string';
            }
        ],
        'email',
        'status',
        'created_at',
    ],
]) !!}

{!! easy_grid([
    'dataProvider' => $dataProvider,
    'columns' => [
        [
            'label' => 'Avatar',
            'attribute' => 'avatar',
            'format' => 'html,
        ],
    ],
]) !!}

{!! easy_grid([
    'dataProvider' => $dataProvider,
    'columns' => [
        'id',
        'name',
        'email',
        'status',
        'created_at',
        [
            'class' => \ChurakovMike\EasyGrid\Columns\ActionColumn::class,
            'buttons' => [
                'show',
                'update',
                'destroy',
            ],
        ],
    ],
]) !!}

{!! easy_grid([
    'dataProvider' => $dataProvider,
    'columns' => [
        'id',
        'name',
        'email',
        'status',
        'created_at',
        [
            'class' => \ChurakovMike\EasyGrid\Columns\ActionColumn::class,
            'buttons' => [
                'show' => function($data) {
                    return route('your-route-name', [
                        'id' => $data->id,
                    ])
                },
                'update' => function($data) {
                    return '/edit/' . $data->id,
                },
                'destroy',
            ],
        ],
    ],
]) !!}

{!! easy_grid([
    'dataProvider' => $dataProvider,
    'columns' => [
        'id',
        [
            'label' => 'Users name',
            'attribute' => 'name',
            'width' => '15%',
        ],
        [
            'label' => 'Custom label',
            'attribute' => 'id',
            'width' => '100px',
        ],
        'email',
        'status',
        'created_at',
    ],
]) !!}