alexeymezenin / laravel-best-practices

Laravel best practices
11.43k stars 2.38k forks source link

Typo Issue in example (Don't repeat yourself (DRY)) #140

Closed Mrabdlrhman closed 2 years ago

Mrabdlrhman commented 2 years ago

In the "Good section" we call the "Active" function which exists in the "Bad section". So correct we need to call the "scopeActive" function

image

Konafets commented 2 years ago

Hey,

the code example in "good" section do not call the active() function from the "bad" section.

  1. there is no active() function in the bad section. Its called getActive() and its not called anywhere.
  2. the good section defines a scope -> activeScope()´ which gets called via->active(). You do not callscopeActive()` as Laravel is smart enough to call that.

Please read the documentation to understand the idea of scopes: https://laravel.com/docs/9.x/eloquent#local-scopes

Mrabdlrhman commented 2 years ago

Hi Konafets,

Thanks for sharing the link.