03 - Filter Multiple Models: With Traits or Relationships
Now, let's add the same user_id to another model: Tasks. We will use two approaches to filter the tasks
We found 16 results for "traits".
Now, let's add the same user_id to another model: Tasks. We will use two approaches to filter the tasks
PHP Traits are a powerful feature that allows you to reuse code in multiple classes without repeating yourself. In this tutorial, I will show 4 examples of how you can use Traits in your Eloquent models.
In a recent video, I've transformed Controller code into a Service class, and some people in the comments argued about using Traits instead. Let me comment on that example, adding a few more examples of Traits in other projects.
I will show you 3 examples of Laravel packages that have the same pattern of interface + trait used together. How does it work, and how can you use it in your projects?
I want to show you practical examples of where Traits are used in Laravel: 3 examples from the Laravel framework itself, and two "bonuses".
Files in the example:
Files in the example:
Files in the example:
Files in the example:
Files in the example:
Files in the example:
Files in the example:
Files in the example:
Files in the example:
Files in the example: