Skip to content

Instantly share code, notes, and snippets.

@niladam
Forked from calebporzio/eloquent_search.php
Created April 11, 2019 20:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niladam/3fa964ea3954d24764a7fb721885bc3a to your computer and use it in GitHub Desktop.
Save niladam/3fa964ea3954d24764a7fb721885bc3a to your computer and use it in GitHub Desktop.
// Add this to the "boot()" method of your "AppServiceProvider"
<?php
\Illuminate\Database\Eloquent\Builder::macro('search', function ($name, $search) {
return $this->where($name, 'LIKE', $search ? '%'.$search.'%' : '');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment