Skip to content

Instantly share code, notes, and snippets.

@msulaimanmisri
Created October 22, 2022 18:03
Show Gist options
  • Save msulaimanmisri/8ed984d25a48791793f0d4647ef46fff to your computer and use it in GitHub Desktop.
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()
/**
* @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