xxxxxxxxxx
// Why do this ..
$users=User :: where(function($query)use($value){
$query->orWhere('name','like',"{$value)")
->orWhere('email','like',"{$value}")
->orWhere('title','like',"{$value}")
->orWhere('role','like',"{$value}%")
->orWhere('status','like',"{$value}%")
})->get();
//...when you can do the same with this?
$users User :: search($value)->get();
xxxxxxxxxx
public function index(){
// // we need to show all data from "blog" table
// $blogs = Blog::all();
// // show data to our view
// return view('blog.index',['blogs' => $blogs]);
$search = Request::get('search');
$blogs = Blog::where('title','like','%'.$search.'%')->orderBy('id')->paginate(6);
return view('blog.index',['blogs' => $blogs]);
}
xxxxxxxxxx
public function index(){
// // we need to show all data from "blog" table
// $blogs = Blog::all();
// // show data to our view
// return view('blog.index',['blogs' => $blogs]);
$search = Request::get('search');
$blogs = Blog::where('title','like','%'.$search.'%')->orderBy('id')->paginate(6);
return view('blog.index',['blogs' => $blogs]);
}
xxxxxxxxxx
public function searchLaptops(Request $request)
{
$brands = Brand::all();
// filter
$laptops = Product::query();
if ($request->latestPopular == 'latest') {
$laptops->orderBy('id', 'desc');
}
if ($request->latestPopular == 'popular') {
$laptops->select('products.*')
->selectSub(
'SELECT AVG(rating) FROM ratings WHERE product_id = products.id',
'average_rating'
)
->orderBy('average_rating', 'desc');
}
if ($request->query('name')) {
$laptops->where('name', 'like', '%' . $request->query('name') . '%');
}
if ($request->query('min')) {
$laptops->where('discount_price', '>=', $request->query('min'));
}
if ($request->query('max')) {
$laptops->where('discount_price', '<=', $request->query('max'));
}
if ($request->query('brand_id')) {
$laptops->where('brand_id', $request->query('brand_id'));
}
if ($request->query('condition')) {
if ($request->query('condition') == 'new') {
$laptops->where('condition', 'new');
} else {
$laptops->where('condition', 'second');
}
}
if ($request->query('status')) {
if ($request->query('status') == 'yes') {
$laptops->where('status', 'yes');
} else {
$laptops->where('status', 'no');
}
}
if ($request->query('search')) {
$laptops->where('name', 'like', '%' . $request->query('search') . '%');
}
$laptops = $laptops->paginate(6);
$laptops->appends(request()->all());
return view('users.search_laptops', compact('brands', 'laptops'));
}
xxxxxxxxxx
// Employee Model
public function searchResult($search)
{
$query = DB::table("employee") ->where('employee_name', 'LIKE', '%'.$search.'%')->get();
return $query;
}
xxxxxxxxxx
// SEARCH QUERY
if (request()->has('search')){
$search = trim(request('search'));
$resumess = $resumess->where(function($query) use ($search){
$query->where('doc_name', 'LIKE', "%{$search}%");
$searches = explode(" ",$search);
foreach($searches as $s){
$query->orWhere('first_name', 'LIKE', "%{$s}%");
$query->orWhere('last_name', 'LIKE', "%{$s}%");
$query->orWhere('position_type', 'LIKE', "%{$s}%");
$query->orWhere('position_type', 'LIKE', "%{$s}%");
}
});
}
xxxxxxxxxx
public function index()
{
$q = Dog::query();
if (Input::has('search'))
{
// simple where here or another scope, whatever you like
$q->where('name','like',Input::get('search'));
}
if (Input::has('search-breed'))
{
$q->searchBreed(Input::get('search-breed'));
}
if (Input::has('sex'))
{
$q->where('sex', Input::get('sex'));
}
if (Input::has('radius'))
{
$q->withinRadius(Input::get('radius'));
}
$dogs = $q->orderBy(..)->paginate(5);
// ...