How to use whereColumn() method in Laravel

Categorized as Laravel Tagged ,

Quick tip: you can use a pretty handy Eloquent method called whereColumn() to verify if columns are equal. For example, you can find posts that have been updated or posts which have the same title and slug. Here is the code:

// Posts that have been updated
  ->whereColumn('updated_at', '>', 'created_at')

// Posts with identical title and slug
  ->whereColumn('title', 'slug')

Read more in the official documentation here.

Leave a reply

Your email address will not be published. Required fields are marked *