本文整理汇总了PHP中app\models\Category::whereIn方法的典型用法代码示例。如果您正苦于以下问题:PHP Category::whereIn方法的具体用法?PHP Category::whereIn怎么用?PHP Category::whereIn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Category
的用法示例。
在下文中一共展示了Category::whereIn方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: categoriesWithProjects
public function categoriesWithProjects()
{
$allCategories = [];
/**
* Seleciona todos os IDs de categorias associadas a projetos
*/
$catsWithProjs = DB::table('category_project')->distinct()->get(['category_id']);
if (count($catsWithProjs) > 0) {
/**
* Reduz o array a apenas IDs
*/
foreach ($catsWithProjs as $value) {
$categories[] = $value->category_id;
}
/**
* Obtem uma Collection de objetos Category
*/
$categoriesOriginal = Category::whereIn('id', $categories)->get();
/**
* Formato amigável para Form::select()
*/
foreach ($categoriesOriginal as $value) {
$allCategories[$value['id']] = $value['name'];
}
}
return $allCategories;
}
示例2: getCategoryFilter
public function getCategoryFilter($id)
{
$child_categories = [];
foreach (Category::all() as $category) {
if ($category->parent_id == $id) {
$child_categories[] = $category->id;
}
}
return view('products.index', ['products' => Product::whereIn('category_id', Category::find($id)->all_children())->get(), 'category' => Category::find($id), 'child_categories' => Category::whereIn('id', $child_categories)->get()]);
}
示例3: getIndex
/**
* 公司真题
*/
public function getIndex()
{
//只显示职业方向和公司分类
$cate_info = Category::where('cate_name', '职业方向')->orwhere('cate_name', '公司')->select(['_id', 'cate_name'])->get();
foreach ($cate_info as $k => &$val) {
$tmp_cate = Category::where('pid', (string) $val->_id)->select(['_id', 'cate_name'])->get();
$val['two_cate'] = $tmp_cate;
}
//搜索最近5年的
$datetime['title'] = '时间';
for ($i = date("Y"); $i > date("Y") - 5; $i--) {
$datetime['times'][] = $i;
}
//默认显示最新
$url = array();
//分页路径
if (!empty($_GET['is_hot'])) {
$id = $_GET['is_hot'];
$where['is_hot'] = '1';
$url['is_hot'] = 1;
} else {
$id = '';
$where['is_news'] = '1';
}
//搜索
$choose_cate = array();
$par = array();
if (!empty($_GET['par'])) {
$par = explode('_', $_GET['par']);
$url['par'] = $_GET['par'];
$choose_cate = Category::whereIn('_id', $par)->select(['_id', 'cate_name'])->get();
$exam_info = Exam::whereIn('job', $par)->orwhereIn('company_id', $par)->where($where)->paginate(3);
} else {
$exam_info = Exam::where($where)->paginate(3);
}
//查询公司logo
foreach ($exam_info as $k => &$val) {
$company_info = Category::where('_id', $val->company_id)->select(['logo'])->first();
$val->company_logo = $company_info->logo;
}
$exam_info->setPath('index');
return view('question.c_exam', ['exam_info' => $exam_info, 'cate_info' => $cate_info, 'choose_cate' => $choose_cate, 'datetime' => $datetime, 'id' => $id, 'par' => $par, 'url' => $url]);
}
示例4: getIndex
/**
* 试题广场
*/
public function getIndex()
{
//只显示职业方向和公司分类
$cate_info = Category::where('pid', '0')->select(['_id', 'cate_name'])->get();
foreach ($cate_info as $k => &$val) {
if ($val->cate_name == '知识点') {
$tmp_cate = Category::where('pid', (string) $val->_id)->where('level', '2')->select(['_id', 'cate_name'])->get();
$val['two_cate'] = $tmp_cate;
foreach ($tmp_cate as $kk => &$vv) {
$tmp_zhishi = Category::where('pid', (string) $vv->_id)->select(['_id', 'cate_name'])->get();
$vv['zhishi'] = $tmp_zhishi;
}
} else {
$tmp_cate = Category::where('pid', (string) $val->_id)->select(['_id', 'cate_name'])->get();
$val['two_cate'] = $tmp_cate;
}
}
//print_R($cate_info);die;
$url = array();
//默认显示最新
if (!empty($_GET['is_hot'])) {
$id = $_GET['is_hot'];
$where['is_hot'] = '1';
$url['is_hot'] = '1';
} else {
$id = '';
$where['is_news'] = '1';
}
//搜索
$choose_cate = array();
$par = array();
$par_arr = array();
$q_type = array();
if (!empty($_GET['par'])) {
$par = explode('_', $_GET['par']);
$par_arr = $par;
$url['par'] = $_GET['par'];
$choose_cate = Category::whereIn('_id', $par)->orwhereIn('cate_name', $par)->select(['_id', 'cate_name'])->get();
foreach ($par as $k => $v) {
$reg = "/^[\\x{4e00}-\\x{9fa5}]+\$/u";
$res = preg_match($reg, $v);
if ($res) {
$q_type[] = $par[$k];
unset($par[$k]);
}
}
if ($par) {
$exam_info = Exam::whereIn('job', $par)->orwhereIn('company_id', $par)->orwhereIn('zhishi', $par)->where($where)->get();
} else {
$exam_info = Exam::where($where)->get();
}
} else {
$exam_info = Exam::where($where)->get();
}
$id_arr = array();
foreach ($exam_info as $k => $val) {
$id_arr[] = $val->_id;
}
if (!$q_type) {
$question_info = Question::whereIn('e_id', $id_arr)->select(['q_title'])->paginate(10);
} else {
$question_info = Question::whereIn('e_id', $id_arr)->whereIn('q_type', $q_type)->select(['q_title'])->paginate(10);
}
//print_R($question_info);
$question_info->setPath('index');
return view('square.square', ['cate_info' => $cate_info, 'question_info' => $question_info, 'id' => $id, 'choose_cate' => $choose_cate, 'par_arr' => $par_arr, 'url' => $url]);
}