🎉 Enjoying this package? Consider sponsoring me on GitHub or buying me a beer.
This is the documentation for v3. You can switch versions in the menu on the left/at the top. Check your current version with the following command:
composer show rappasoft/laravel-livewire-tables
Text Filters
Text filters are just simple text filters, allowing you to pass a string value into a builder query.
1public function filters(): array 2{ 3 return [ 4 TextFilter::make('Name') 5 ->config([ 6 'placeholder' => 'Search Name', 7 'maxlength' => '25', 8 ]) 9 ->filter(function(Builder $builder, string $value) {10 $builder->where('users.name', 'like', '%'.$value.'%');11 }),12 ];13}
Extra Helpers
There are a number of helpers to simplify your code, should you not wish to rewrite the filter function repeatedly for a Text Filter. You can only use one of the below methods per-filter.
Contains
This executes the filter and returns results where the field contains the filter value
1public function filters(): array 2{ 3 return [ 4 TextFilter::make('Name') 5 ->config([ 6 'placeholder' => 'Search Name', 7 'maxlength' => '25', 8 ]) 9 ->contains('users.name'),10 ];11}
notContains
This executes the filter and returns results where the field does not contain filter value
1public function filters(): array 2{ 3 return [ 4 TextFilter::make('Name') 5 ->config([ 6 'placeholder' => 'Search Name', 7 'maxlength' => '25', 8 ]) 9 ->notContains('users.name'),10 ];11}
startsWith
This executes the filter and returns results where the field starts with the filter value
1public function filters(): array 2{ 3 return [ 4 TextFilter::make('Name') 5 ->config([ 6 'placeholder' => 'Search Name', 7 'maxlength' => '25', 8 ]) 9 ->startsWith('users.name'),10 ];11}
notStartsWith
This executes the filter and returns results where the field does not start with the filter value
1public function filters(): array 2{ 3 return [ 4 TextFilter::make('Name') 5 ->config([ 6 'placeholder' => 'Search Name', 7 'maxlength' => '25', 8 ]) 9 ->notStartsWith('users.name'),10 ];11}
endsWith
This executes the filter and returns results where the field ends with the filter value
1public function filters(): array 2{ 3 return [ 4 TextFilter::make('Name') 5 ->config([ 6 'placeholder' => 'Search Name', 7 'maxlength' => '25', 8 ]) 9 ->endsWith('users.name'),10 ];11}
notEndsWith
This executes the filter and returns results where the field does not end with the filter value
1public function filters(): array 2{ 3 return [ 4 TextFilter::make('Name') 5 ->config([ 6 'placeholder' => 'Search Name', 7 'maxlength' => '25', 8 ]) 9 ->notEndsWith('users.name'),10 ];11}
setFieldName
An optional method for setting the field to use when filtering, if used, you may omit the field from the above methods, for example:
1public function filters(): array 2{ 3 return [ 4 TextFilter::make('Name') 5 ->config([ 6 'placeholder' => 'Search Name', 7 'maxlength' => '25', 8 ]) 9 ->setFieldName('users.name')10 ->contains(),11 ];12}