I remember when I was learning ruby there was a DRY rule used everywhere (Do not Repeat Yourself).
Are traits in php the only similat thing or is there some other way thal will allow me reuse pieces of my code. I mean not even a function but a piece of a funtion maybe?
Ok so what tou say is to create a Trait with all the junk small functions that I need and then to import that to my controllers.
But is there a way for even like code snippets? Lets say I search a model in few places in my code and the only difference is that sometimes search results are paginated some are a take(20) and some are get() but the proceedeing params are always the same.
Can I DRY this somehow?
I understand Trait and function gut I can not really chain those to have different end params.
If I create a function at the model I think the same problem will arise?
This question is a bit vague. DRY is not something ruby specific it is just a good way to program in general. DRY should always be the end goal. Since you are asking this question on laracasts here are some php/laravel related examples:
traits
parent/child classes
partials for views
components for views
extracting classes for a piece of functionality
extracting common tasks to dedicated classes
making a repository to bundle code
make a global helpers file for general helper function
all design patterns
..
its pretty much endless , so you need to be more specific and show an example of what piece of code you would like to make dry.