PHP code example of netflex / livewire-tables

1. Go to this page and download the library: Download netflex/livewire-tables 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/ */

    

netflex / livewire-tables example snippets




namespace App\Http\Livewire;

use App\Article;
use Netflex\Query\Builder;

use Netflex\Livewire\Tables\TableComponent;
use Netflex\Livewire\Tables\Traits\HtmlComponents;
use Netflex\Livewire\Tables\Views\Column;

class ArticleTable extends TableComponent
{
    use HtmlComponents;

    public function query() : Builder
    {
        return Article::query()->ignorePublishingStatus();
    }

    public function columns() : array
    {
        return [
            Column::make('ID')
                ->searchable()
                ->sortable(),
            Column::make('Image')
                ->format(function(Article $article) {
                    return $this->image($article->image, 'tableArticlePreset', $article->name, ['class' => 'img-fluid']);
                }),
            Column::make('Name')
                ->searchable()
                ->sortable(),
            Column::make('E-mail', 'email')
                ->searchable()
                ->sortable()
                ->format(function(Article $article) {
                    return $this->mailto($article->email, null, ['target' => '_blank']);
                }),
            Column::make('Actions')
                ->format(function(Article $article) {
                    return view('backend.auth.user.

/**
 * This defines the start of the query, usually Model::query() but can add additonal constraints to the query.
 */
public function query() : Builder;

/**
 * This defines the columns of the table, they don't necessarily have to map to fields in the model structure.
 */
public function columns() : array;


/**
 * The first argument is the column header text
 * The attribute can be omitted if the text is equal to the lower case snake_cased version of the column
 * The attribute can also be used to reference a relationship (i.e. role.name)
 */
public function make($text, ?$attribute) : Column;

/**
 * Used to format the column data in different ways, see the HTML Components section.
 * You will be passed the current model and column (if you need it for some reason) which can be omitted as an argument if you don't need it.
 */
public function format(callable $callable = null) : self;

/**
 * This column is searchable, with no callback it will search the column by name or by the supplied relationship, using a callback overrides the default searching functionality.
 */
public function searchable(callable $callable = null) : self;

/**
 * This column is sortable, with no callback it will sort the column by name and sort order defined on the components $sortDirection variable
 */
public function sortable(callable $callable = null) : self;

/**
 * The columns output will be put through {!! !!} instead of {{ }}.
 */
public function raw() : self;

/**
 * Hide this column permanently
 */
public function hide() : self;

/**
 * Hide this column based on a condition. i.e.: user has or doesn't have a role or permission. Must return a boolean, not a closure.
 */
public function hideIf($condition) : self;

/**
 * This column is only 

public function setTableHeadClass($attribute): ?string
public function setTableHeadId($attribute): ?string
public function setTableHeadAttributes($attribute): array
public function setTableRowClass($article): ?string
public function setTableRowId($article): ?string
public function setTableRowAttributes($article): array
public function getTableRowUrl($article): ?string
public function setTableDataClass($attribute, $value): ?string
public function setTableDataId($attribute, $value): ?string
public function setTableDataAttributes($attribute, $value): array

public function updatingSearch(): void
public function updatingPerPage(): void

public function clearSearch(): void

public function sort($attribute): void

public function image($pathOrMediaUrlResolvable, $presetOrSize, $alt = null, $attributes = []): HtmlString
public function link($url, $title = null, $attributes = [], $secure = null, $escape = true): HtmlString
public function secureLink($url, $title = null, $attributes = [], $escape = true): HtmlString
public function linkAsset($url, $title = null, $attributes = [], $secure = null, $escape = true): HtmlString
public function linkSecureAsset($url, $title = null, $attributes = [], $escape = true): HtmlString
public function linkRoute($name, $title = null, $parameters = [], $attributes = [], $secure = null, $escape = true): HtmlString
public function linkAction($action, $title = null, $parameters = [], $attributes = [], $secure = null, $escape = true): HtmlString
public function mailto($email, $title = null, $attributes = [], $escape = true): HtmlString
public function email($email): string
public function html($html): HtmlString



namespace App\Http\Livewire;

use App\Article;

use Netflex\Query\Builder;
use Netflex\Livewire\Tables\TableComponent;
use Netflex\Livewire\Tables\Traits\HtmlComponents;
use Netflex\Livewire\Tables\Views\Column;

class ArticleTable extends TableComponent
{
    use HtmlComponents;

    public function query() : Builder
    {
        return Article::query()->ignorePublishingStatus();
    }

    public function columns() : array
    {
        return [
            Column::make('ID')
                ->searchable()
                ->sortable()
                ->excludeFromExport(), // This column is visible to the UI, but not export.
            Column::make('ID')
                ->exportOnly(), // This column is only rendered on export
            Column::make('Image')
                ->format(function(User $article) {
                    return $this->image($article->image, 'presetName', $article->name, ['class' => 'img-fluid']);
                })
                ->excludeFromExport(), // This column is visible to the UI, but not export.
            Column::make('Name') // This columns is visible to both the UI and export, and is rendered the same
                ->searchable()
                ->sortable(),
            Column::make('E-mail', 'email')
                ->searchable()
                ->sortable()
                ->format(function(Article $article) {
                    return $this->mailto($article->email, null, ['target' => '_blank']);
                })
                ->exportFormat(function(User $article) { // This column is visible to both the UI and the export, but is formatted differently to the export via this method.
                    return $article->email;
                }),
            Column::make('Actions')
                ->format(function(User $article) {
                    return view('backend.auth.user.

protected $options = [
    // The class set on the table
    'classes.table' => 'table table-striped table-bordered',

    // The class set on the table's thead
    'classes.thead' => null,

    // The class set on the table's export dropdown button
    'classes.buttons.export' => 'btn btn-secondary',
    
    // Whether or not the table is wrapped in a `.container-fluid` or not
    'container' => true,
    
    // Whether or not the table is wrapped in a `.table-responsive` or not
    'responsive' => true,
];

<livewire:article-table status="{{ request('status') }}" />

protected $status = 'active';

public function mount($status) {
    $this->status = $status;
}
 bash
php artisan vendor:publish --provider="Netflex\Livewire\Tables\LivewireTablesServiceProvider" --tag=views

php artisan vendor:publish --provider="Netflex\Livewire\Tables\LivewireTablesServiceProvider" --tag=lang