Uploaded August 2025 | Updated September 2026, 19 minutes ago
What if your code could read the way you wish the framework worked? I'll show you how I built a powerful Laravel helper for finding all models that use a given trait starting with a made-up interface and ending with a flexible reflection-based collection.
Follow me:
Twitter: twitter.com/aarondfrancis
LinkedIn: linkedin.com/in/aarondfrancis
Website: aaronfrancis.com - find articles, podcasts, courses, and more.
Chapters:
00:00 - Programming by wishful thinking
00:16 - The 'ModelsThat:useTrait' idea
00:47 - The hasEmbedding trait pattern
01:31 - Abstract methods for embeddings
02:29 - Applying the trait to different models
03:13 - Trait-provided relationships and scopes
03:54 - Writing the embeddings:create command
04:44 - Starting the helper: modelsThatUseTrait
06:00 - Scanning files and resolving class names
07:02 - Converting paths to PSR-4 class names
08:03 - Using ReflectionClass to inspect traits
09:00 - Filtering models by trait usage
10:12 - Returning class names as a collection
11:00 - Verifying the helper works
11:16 - Next step: creating
What if your code could read the way you wish the framework worked? I'll show you how I built a powerful Laravel helper for finding all models that use a given trait starting with a made-up interface and ending with a flexible reflection-based collection.
Follow me:
Twitter: twitter.com/aarondfrancis
LinkedIn: linkedin.com/in/aarondfrancis
Website: aaronfrancis.com - find articles, podcasts, courses, and more.
Chapters:
00:00 - Programming by wishful thinking
00:16 - The 'ModelsThat:useTrait' idea
00:47 - The hasEmbedding trait pattern
01:31 - Abstract methods for embeddings
02:29 - Applying the trait to different models
03:13 - Trait-provided relationships and scopes
03:54 - Writing the embeddings:create command
04:44 - Starting the helper: modelsThatUseTrait
06:00 - Scanning files and resolving class names
07:02 - Converting paths to PSR-4 class names
08:03 - Using ReflectionClass to inspect traits
09:00 - Filtering models by trait usage
10:12 - Returning class names as a collection
11:00 - Verifying the helper works
11:16 - Next step: creating










