最近发表的话题
最近发表的评论
  • 这句查询 with ('user') 是如何用到的查询的就是微博数据为什么和 user 表有关系??求大神详细解答。 at 4个月前

    这里面的with绝对是多余的。我把非with的和有with的方式都打印出来了。

    打印出的数组为

    with后:

    [0] => Array
        (
            [query] => select * from `users` where `id` = ? limit 1
            [bindings] => Array
                (
                    [0] => 105
                )
    
            [time] => 11.1
        )
    
    [1] => Array
        (
            [query] => select `users`.*, `followers`.`follower_id` as `pivot_follower_id`, `followers`.`user_id` as `pivot_user_id` from `users` inner join `followers` on `users`.`id` = `followers`.`user_id` where `followers`.`follower_id` = ?
            [bindings] => Array
                (
                    [0] => 105
                )
    
            [time] => 0.43
        )
    
    [2] => Array
        (
            [query] => select count(*) as aggregate from `statuses` where `user_id` in (?, ?, ?, ?)
            [bindings] => Array
                (
                    [0] => 101
                    [1] => 102
                    [2] => 3
                    [3] => 105
                )
    
            [time] => 0.49
        )
    
    [3] => Array
        (
            [query] => select * from `statuses` where `user_id` in (?, ?, ?, ?) order by `created_at` desc limit 30 offset 120
            [bindings] => Array
                (
                    [0] => 101
                    [1] => 102
                    [2] => 3
                    [3] => 105
                )
    
            [time] => 1.3
        )
    
    [4] => Array
        (
            [query] => select * from `users` where `users`.`id` in (?, ?, ?)
            [bindings] => Array
                (
                    [0] => 101
                    [1] => 102
                    [2] => 105
                )
    
            [time] => 0.32
        )

    非with:

    [0] => Array
        (
            [query] => select * from `users` where `id` = ? limit 1
            [bindings] => Array
                (
                    [0] => 105
                )
    
            [time] => 10.52
        )
    
    [1] => Array
        (
            [query] => select `users`.*, `followers`.`follower_id` as `pivot_follower_id`, `followers`.`user_id` as `pivot_user_id` from `users` inner join `followers` on `users`.`id` = `followers`.`user_id` where `followers`.`follower_id` = ?
            [bindings] => Array
                (
                    [0] => 105
                )
    
            [time] => 0.34
        )
    
    [2] => Array
        (
            [query] => select count(*) as aggregate from `statuses` where `user_id` in (?, ?, ?, ?)
            [bindings] => Array
                (
                    [0] => 101
                    [1] => 102
                    [2] => 3
                    [3] => 105
                )
    
            [time] => 0.28
        )
    
    [3] => Array
        (
            [query] => select * from `statuses` where `user_id` in (?, ?, ?, ?) order by `created_at` desc limit 30 offset 120
            [bindings] => Array
                (
                    [0] => 101
                    [1] => 102
                    [2] => 3
                    [3] => 105
                )
    
            [time] => 1.3
        )

    这里证明非with照样可以取出用户数据而且少了一条sql,作者能帮忙解释下么

  • 【扩展推荐】Laravel-uuid 通用唯一识别码 at 4个月前

    请问这个uuid能不能int化呢?