protonemedia / laravel-splade

💫 The magic of Inertia.js with the simplicity of Blade 💫 - Splade provides a super easy way to build Single Page Applications (SPA) using standard Laravel Blade templates, and sparkle it to make it interactive. All without ever leaving Blade.
https://splade.dev
MIT License
1.47k stars 111 forks source link

Pass parameter to table #510

Closed EmilMoe closed 7 months ago

EmilMoe commented 1 year ago

Description:

How can I display a table on a sub page for a group, where I only want a subgroup from the table to be displayed? I don't see a way to pass any parameters to the table class.

Documentation says:

Note that this will apply to all results. So, for example, if you want to choose in the frontend between admins and non-admins, this is not the right place to use the constraint.

But not how the right way should be then.

https://splade.dev/docs/table-overview

Preferably there would be some attributes.

Steps To Reproduce Issue:

Creating a dynamically scoped table.

EmilMoe commented 1 year ago

I figured it can be done in the controller, but still interested if it's possible with a Table class.

'table' => SpladeTable::for(Model::where('parent', $id))
jadetulda1996 commented 1 year ago

Hi!

You may use the Table class' constructor by creating an instance.

In the controller: $myTable = new TableClass($groupId);

In the table class: public function __construct(private $groupId) {}

And you may now use the property $groupId inside the table class.