zoukankan      html  css  js  c++  java
  • tp5怎么关联模型进行条件查询?

     

    // 查询用户昵称是think的用户

    // 注意第一个参数是关联方法名(不是关联模型名)

    $users = User::hasWhere('profile', ['nickname'=>'think'])->select();

     

    // 可以使用闭包查询

    $users = User::hasWhere('profile', function($query) {

        $query->where('nickname', 'like', 'think%');

    })->select();

     

    模型里面

        public function authGroupAccess()

        {

            return $this->belongsTo('authGroupAccess''id''uid')->bind('group_id');

        }

     

    控制器里面:

    hasWhere的使用

       

    if (!empty($param['group_id'])) {

                $haswhere['group_id'= $param['group_id'];

    }

     

     

    $list = model('admin')

                ->hasWhere('authGroupAccess', $haswhere)

                ->with('authGroupAccess,authGroup')

                ->where('username''neq''admin')

                ->order('id','desc')

                ->where($where)

                ->paginate(config('page_number'));

     

     

    文章来源:刘俊涛的博客 欢迎关注公众号、留言、评论,一起学习。

     

    若有帮助到您,欢迎点击推荐,您的支持是对我坚持最好的肯定(*^_^*)

  • 相关阅读:
    guxh的python笔记一:数据类型
    guxh的python笔记三:装饰器
    guxh的python笔记十:包和模块
    guxh的python笔记六:类的属性
    guxh的python笔记四:迭代
    流畅的python笔记
    spring面试大全
    Spring面试问答
    Hibernate的10个常见面试问题及答案
    reflect 机制
  • 原文地址:https://www.cnblogs.com/lovebing/p/12884086.html
Copyright © 2011-2022 走看看