Skip to content

Commit

Permalink
Merge pull request #6 from suenerds/issue-1
Browse files Browse the repository at this point in the history
PR: Filter title
  • Loading branch information
anotherfrontendguy authored Jan 21, 2020
2 parents c8210d6 + 14e6779 commit e66d89d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ This package assumes you have a text-search setup for your Eloquent models. See
For this example let's assume a user belongs to a department and a department has many users.
To make the relationship searchable via a filter, add this to the `filters()` function of your Nova user resource:

By default the filter will display the name of the `fieldAttribute` you passed on instantiation. You can customize the name by passing it as an argument to the filter's construct function, for example `my-new-name`.

```php
// app/Nova/User.php
public function filters(Request $request)
{
return [
(new NovaSearchableBelongsToFilter)
(new NovaSearchableBelongsToFilter('my-new-name'))
->fieldAttribute('department')
->filterBy('department_id')
];
}
```
```
7 changes: 6 additions & 1 deletion src/NovaSearchableBelongsToFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ class NovaSearchableBelongsToFilter extends Filter

public $filterBy;

public function __construct($name = '')
{
$this->name = $name;
}

/**
* Apply the filter to the given query.
*
Expand All @@ -42,7 +47,7 @@ public function options(Request $request)

public function name()
{
return __('Filter by ' . $this->getFieldAttribute());
return __($this->name ?: $this->getFieldAttribute());
}

public function fieldAttribute($attribute)
Expand Down

0 comments on commit e66d89d

Please sign in to comment.