Deprecated: Function create_function() is deprecated in /var/www/html/wp-includes/pomo/translations.php on line 208

Notice: wp_deregister_script的调用方法不正确。脚本和样式应在wp_enqueue_scriptsadmin_enqueue_scriptslogin_enqueue_scripts钩子之后再加入加载队列(enqueue)或注册(register)。 请查阅调试WordPress来获取更多信息。 (这个消息是在3.3版本添加的。) in /var/www/html/wp-includes/functions.php on line 3897

Notice: Undefined variable: control_ops in /var/www/html/wp-content/themes/yusi1.0/widgets/wid-banner.php on line 11

Notice: 在d_banner中为WP_Widget调用的构造函数已自版本4.3.0起废弃!请改用
__construct()
。 in /var/www/html/wp-includes/functions.php on line 3718

Notice: Undefined variable: control_ops in /var/www/html/wp-content/themes/yusi1.0/widgets/wid-readers.php on line 11

Notice: 在d_reader中为WP_Widget调用的构造函数已自版本4.3.0起废弃!请改用
__construct()
。 in /var/www/html/wp-includes/functions.php on line 3718

Notice: Undefined variable: control_ops in /var/www/html/wp-content/themes/yusi1.0/widgets/wid-postlist.php on line 11

Notice: 在d_postlist中为WP_Widget调用的构造函数已自版本4.3.0起废弃!请改用
__construct()
。 in /var/www/html/wp-includes/functions.php on line 3718

Notice: Undefined variable: control_ops in /var/www/html/wp-content/themes/yusi1.0/widgets/wid-comment.php on line 11

Notice: 在d_comment中为WP_Widget调用的构造函数已自版本4.3.0起废弃!请改用
__construct()
。 in /var/www/html/wp-includes/functions.php on line 3718

Notice: Undefined variable: control_ops in /var/www/html/wp-content/themes/yusi1.0/widgets/wid-tags.php on line 11

Notice: 在d_tag中为WP_Widget调用的构造函数已自版本4.3.0起废弃!请改用
__construct()
。 in /var/www/html/wp-includes/functions.php on line 3718

Notice: Undefined variable: control_ops in /var/www/html/wp-content/themes/yusi1.0/widgets/wid-textbanner.php on line 11

Notice: 在d_textbanner中为WP_Widget调用的构造函数已自版本4.3.0起废弃!请改用
__construct()
。 in /var/www/html/wp-includes/functions.php on line 3718

Notice: Undefined variable: control_ops in /var/www/html/wp-content/themes/yusi1.0/widgets/wid-subscribe.php on line 11

Notice: 在d_subscribe中为WP_Widget调用的构造函数已自版本4.3.0起废弃!请改用
__construct()
。 in /var/www/html/wp-includes/functions.php on line 3718
laravel使用模型关联with问题 - 永盟博客永盟博客
去发现生活中的美好,记录生活中的点点滴滴

laravel使用模型关联with问题

php admin 1466℃

1、在laravel使用with关联模型的时候,需要指定字段输出,这个时候,发现返回的值为空,经排查,是因为关联的id没有全部放出来查询:

    public function user(){
        return $this->hasMany('App\Model\UserModel', 'org_id', 'id');
    }

//返回空

Org::with(array('user'=>function($query){
    $query->select('username');
}))->get();

需把关联的字段也查询,才有数据:

Org::with(array('user'=>function($query){
    $query->select('id','org_id','username');
}))->get();

转载请注明:永盟博客 » laravel使用模型关联with问题

喜欢 (2)

Notice: compact(): Undefined variable: limits in /var/www/html/wp-includes/class-wp-comment-query.php on line 853

Notice: compact(): Undefined variable: groupby in /var/www/html/wp-includes/class-wp-comment-query.php on line 853

Warning: count(): Parameter must be an array or an object that implements Countable in /var/www/html/wp-includes/class-wp-comment-query.php on line 405