Skip to content

Instantly share code, notes, and snippets.

@nickclasener
Forked from calebporzio/eloquent_search.php
Created April 12, 2019 21:01
Show Gist options
  • Save nickclasener/633eec440977272a7af4cdeb70e6ea70 to your computer and use it in GitHub Desktop.
Save nickclasener/633eec440977272a7af4cdeb70e6ea70 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