Created
October 22, 2022 18:03
-
-
Save msulaimanmisri/8ed984d25a48791793f0d4647ef46fff to your computer and use it in GitHub Desktop.
This syntax will make your development faster without need to type each time you want to render PHP syntax such as ucwords() or preg_replace()
This file contains 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
/** | |
* @author Muhamad Sulaiman Misri | |
*/ | |
trait TransformOrderTitle { | |
protected function orderTitle(): Attribute { | |
return Attribute::make( | |
/** | |
* This will show your string as Uppercase. | |
*/ | |
get:fn($value) => ucwords($value), | |
/** | |
* This will remove all HTML special chars and save only string on your DB | |
*/ | |
set:fn($value) => preg_replace('/[^A-Za-z0-9\-]/', '', $value), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment