Last active
March 18, 2021 20:28
-
-
Save JHWelch/8579847ce6bfe87fe469b29309e2be23 to your computer and use it in GitHub Desktop.
Laravel Nova Text Field Limit Macro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Text Field Limit Macro | |
* Implementation of Str::limit Helper. | |
* Truncates a string after $limit characters and adds $end | |
* Can be added to NovaServiceProvider in boot() | |
*/ | |
\Laravel\Nova\Fields\Text::macro('limit', function ($limit = 50, $end = '...') { | |
$this->displayUsing( | |
function ($text) use ($limit, $end) { | |
return \Illuminate\Support\Str::limit($text, $limit, $end); | |
} | |
); | |
return $this; | |
}); | |
/* | |
* Example | |
*/ | |
Text::make('First Name') | |
->sortable() | |
->rules('required') | |
->limit(20, '->'), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment