Skip to content

Instantly share code, notes, and snippets.

@saaiful
Created July 5, 2018 07:50
Show Gist options
  • Select an option

  • Save saaiful/dbf3728c6942df25faebea418338c949 to your computer and use it in GitHub Desktop.

Select an option

Save saaiful/dbf3728c6942df25faebea418338c949 to your computer and use it in GitHub Desktop.
@saaiful
Copy link
Author

saaiful commented Jul 5, 2018

$model = $model->where(function ($query) { $query->where('name', 'LIKE', $this->q) ->orWhere('short_description', 'LIKE', $this->q) ->orWhere('description', 'LIKE', $this->q) ->orWhere('keywords', 'LIKE', $this->q); });

This is the search part, which uses LIKE for searching. Though I implemented a searching system with Scout & T&T

@saaiful
Copy link
Author

saaiful commented Jul 5, 2018

Issue Resolved Using RawOrder
$model->orderByRaw("CASE WHEN instr(name, '" . $request->q . "') = 0 then 1 else 0 end, instr(name, '" . $request->q . "') desc");

@saaiful
Copy link
Author

saaiful commented Jul 5, 2018

Finalized Using:
$model->orderByRaw("CASE WHEN instr(name, '" . escape($request->q) . "') = 0 then 1 else 0 end, instr(name, '" . escape($request->q) . "') desc");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment