Skip to content

Instantly share code, notes, and snippets.

@calebporzio
Last active November 23, 2021 15:01
Show Gist options
  • Save calebporzio/a85538fd506421448f68a97309355f1b to your computer and use it in GitHub Desktop.
Save calebporzio/a85538fd506421448f68a97309355f1b 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