Sending variable to data table component #769
-
Hi! I was testing Request::segment(2) just to get the ID to test and it was working, but it would be better to pass it like a variable for many reasons.
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
In the latest version you can pass variables through mount just like you would expect. Here is an extreme example 🤯 public ?string $dbTableName;
public function mount($dbTableName = null)
{
$this->dbTableName = $dbTableName;
}
/**
* The base query.
*/
public function builder() : Builder
{
if(!isset($this->dbTableName)) {
return parent::builder();
}
$model = new class extends \Illuminate\Database\Eloquent\Model {
};
$model->setTable($this->dbTableName);
return $model->getQuery();
} Keep in mind that that only certain types of properties can be persisted on re-render as per Livewire Docs |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot! That did it. |
Beta Was this translation helpful? Give feedback.
In the latest version you can pass variables through mount just like you would expect. Here is an extreme example 🤯
Keep in mind that that only certain types of properties can be persisted on re-render as per L…