Okipa / laravel-table

Generate tables from Eloquent models.
MIT License
532 stars 64 forks source link

How to use identifier() #38

Closed chris5560 closed 4 years ago

chris5560 commented 4 years ago

Hi, I'm very sorry, it's well described how to set an identifier for a table and when to use it but it's missing how to implement multiple tables with their identifier inside one view. Thanks for your support. Christian

Okipa commented 4 years ago

Hi @chris5560, you have to declare as much as tables as you want and send them to the view.

You would have to do this in your controller for example:

public function index()
{
    $usersTable = (new \Okipa\LaravelTable\Table)
    ->model(\App\User::class)
    ->routes(['index' => ['name' => 'users.index']])
    ->identifier('Users table');
    $usersTable->column('name')->sortable()->searchable();

    $newsTable = (new \Okipa\LaravelTable\Table)
    ->model(\App\News::class)
    ->routes(['index' => ['name' => 'news.index']])
    ->identifier('News table');
    $newsTable->column('title')->sortable()->searchable();

    return view('your.view.path', compact('usersTable', 'newsTable'));
}

And then in your view:

    {{ $usersTable }}

    {{ $newsTable }}

This way, your will be able to realize actions like searching or sorting independently for each table.