Traits are a collection of reusable methods that are accessible in multiple classes. It shares code between classes that are not related by inheritance.
To access these methods in a class first need to define the trait using the use
keyword and call the method using $this
if it is not a static method otherwise use self::
.
In this tutorial, I show how you can create and use Traits in the Controller in Laravel 10.