-
composer.json
Open in GitHub{ "require": { "php": "^7.3", // "nicolaslopezj/searchable": "^1" }, }
-
app/Discussion.php
Open in GitHubuse Illuminate\Database\Eloquent\Model; use Nicolaslopezj\Searchable\SearchableTrait; class Discussion extends Model { use SearchableTrait; protected $searchable = [ 'columns' => [ 'discussions.name' => 10, 'discussions.body' => 10, ], ]; }
-
app/File.php
Open in GitHubuse Nicolaslopezj\Searchable\SearchableTrait; class File extends Model { use SearchableTrait; protected $searchable = [ 'columns' => [ 'files.name' => 10, ], ]; }
-
app/Http/Controllers/SearchController.php
Open in GitHubclass SearchController extends Controller { public function index(Request $request) { if ($request->get('query')) { $query = $request->get('query'); $discussions = \App\Discussion::whereIn('group_id', $allowed_groups) ->with('group') ->search($query) ->orderBy('updated_at', 'desc') ->paginate(20, ['*'], 'discussions'); $files = \App\File::whereIn('group_id', $allowed_groups) ->with('group') ->search($query) ->orderBy('updated_at', 'desc') ->paginate(20, ['*'], 'files'); // } }