首页 > 解决方案 > 在搜索结果中显示 2 列中 1 个表的信息。(PHP - Laravel)

问题描述

标签: phpmysqllaravellaravel-5

解决方案


<?php 

// To get both the jobs : 

$allJobs = $jobs->where('status', 'active')->paginate(15);

// To get al basic jobs 

$allBasicJobs = $jobs->where('status', 'active')->where('type', 'basic')->paginate(15);

// To get all premium jobs 

$allBasicJobs = $jobs->where('status', 'active')->where('type', 'op2')->paginate(15);

// To search title in  basic jobs but get all premier jobs

$filteredBasicJobsAllPremiumJobs = $jobs->where('status', 'active')
                                        ->where('type', 'op2')
                                        ->orWhere(function($q) use($request){
                                            return $q->where('type', 'basic')
                                                ->where('title', 'like', '%' . $request->q . '%');
                                        })
                                        ->paginate(15);

// To search title in  permium jobs but get all basic jobs

$filteredPremiumJobsAllBasicJobs = $jobs->where('status', 'active')
                                        ->where('type', 'basic')
                                        ->orWhere(function($q) use($request){
                                            return $q->where('type', 'op2')
                                                ->where('title', 'like', '%' . $request->q . '%');
                                        })
                                        ->paginate(15);

// To search title in both basic and premium jobs

$filteredJobs = $jobs->where('status', 'active')
                    ->where('title', 'like', '%' . $request->q . '%')
                    ->paginate(15);

推荐阅读