Skip to content

Commit d114145

Browse files
committed
Add getColumn() in SublimeSearch. Fix cs
1 parent 548d387 commit d114145

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/Search/SublimeSearch.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,38 @@ public function query()
8383
return $this->query;
8484
}
8585

86+
/**
87+
* Get the actual searchable column of the given column key.
88+
*
89+
* @param string $columnKey
90+
* @return string|mixed
91+
*/
92+
public function getColumn($columnKey)
93+
{
94+
$columns = $this->searchable();
95+
96+
if (array_key_exists($columnKey, $columns)) {
97+
return $columns[$columnKey];
98+
}
99+
100+
foreach ($columns as $column) {
101+
if ($column === $columnKey || ends_with($column, ".{$columnKey}")) {
102+
return $column;
103+
}
104+
}
105+
}
106+
107+
/**
108+
* Getter for searchable column.
109+
*
110+
* @param string $columnKey
111+
* @return string|mixed
112+
*/
113+
public function __get($columnKey)
114+
{
115+
return $this->getColumn($columnKey);
116+
}
117+
86118
/**
87119
* Apply search query.
88120
*

src/SearchableModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Illuminate\Support\Facades\Schema;
77

88
/**
9-
* Deprecated. Use SublimeSearch instead
9+
* Deprecated. Use SublimeSearch instead.
1010
*/
1111
class SearchableModel extends BaseGridQuery
1212
{

0 commit comments

Comments
 (0)