reinink/advanced-eloquent

Suggestion: add macros which help avoid key comparisons

Closed this issue · 1 comments

Since primary/foreign key names are defined/inherited when creating a model or relation, it feels like Repeating Yourself to do comparisons like where('id', $model->id) or where('user_id', $user->id).

  • $query->whichIs($model):

    $query->whereKey($model->getKey())
  • $query->hasWhichIs('relation', $model) (or some less awkward name):

    $query->whereHas('relation', function ($query) {
      return $query->whichIs($model);
    });

    Get posts with $tag: Post::hasWhichIs('tags', $tag)

Hey thanks for the suggestion, but since I'm pushing more of the functionality from this package to the core of Laravel, I'll likely end up archiving this project eventually...not adding more features to it.