How to use traits in Laravel 5.4.18?

-1

Where to create exactly the file, what to write in it, and how to use the functions declared in the trait. I use Laravel Framework 5.4.18

- I have not altered any folder of the framework, everything is where it belongs -

Thank you in advance.

    
asked by emi 16.04.2017 в 05:07
source

1 answer

2

A trait is just another PHP functionality, it has nothing to do with Laravel or any other Framework: link

Answering the questions:

  

How to use traits in Laravel?

Same as they would be used in "pure" PHP.

  

Where exactly to create the file?

Probably in the app/ folder in the subfolder that you consider appropriate based on the design of your application.

  

What to write in it?

The same as you would write in any other trait, without forgetting the corresponding namespace.

  

How to use the functions declared in the trait?

In the same way you would use them in any other PHP project.

    
answered by 16.04.2017 / 05:33
source