Access model class
Zzombiee2361 opened this issue · 2 comments
Zzombiee2361 commented
I need the model class in my filter class to get the table name. For example I have multiple table with similar status
column, so I make a StatusFilter
trait to all filter class that need to filter status. This would be fine unless I join a table also with status column in it, so for that case I need to include the table name.
trait StatusFilter {
public function status($status) {
$table = (new $this->model)->getTable(); // I need the model class here
$this->where("{$table}.status", $status);
}
}
Tucker-Eric commented
You have access to the underlying QueryBuilder so you should be able to do:
trait StatusFilter {
public function status($status) {
$table = $this->query->getModel()->getTable();
$this->where("{$table}.status", $status);
}
}
Zzombiee2361 commented
Ah I didn't know about the getModel()
method. And I could use get_class()
if I really need the class