Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在主模型的Laravel雄辩连接查询中使用AS关键字_Php_Laravel_Laravel 5_Eloquent - Fatal编程技术网

Php 在主模型的Laravel雄辩连接查询中使用AS关键字

Php 在主模型的Laravel雄辩连接查询中使用AS关键字,php,laravel,laravel-5,eloquent,Php,Laravel,Laravel 5,Eloquent,我想在Laravel雄辩模型中使用作为关键字,如下所示: 下面是我的示例查询: User::find(1) ->select("name", "age") ->join("profile as p", "p.user_id", "=", "users.id") ->orderBy("name", "asc") ->get(); 在与主表/模型的联接上预期使用u.id而不是users.id ->join("profile as p",

我想在Laravel雄辩模型中使用
作为
关键字,如下所示:

下面是我的示例查询:

User::find(1)
    ->select("name", "age")
    ->join("profile as p", "p.user_id", "=", "users.id")
    ->orderBy("name", "asc")
    ->get();
在与主表/模型的联接上预期使用
u.id
而不是
users.id

->join("profile as p", "p.user_id", "=", "u.id")

有这样的功能吗?有可能吗?

像那样雄辩地使用
方法中的

User::from('users as u')->find(1)
    ->select("name", "age")
    ->join("profile as p", "p.user_id", "=", "u.id")
    ->orderBy("name", "asc")
    ->get();

查看此查询雄辩的方法

使用类似雄辩的方法中的
from
方法

User::from('users as u')->find(1)
    ->select("name", "age")
    ->join("profile as p", "p.user_id", "=", "u.id")
    ->orderBy("name", "asc")
    ->get();

查看此查询雄辩的方法

我看到的@Fawzan的可能重复,这是一个非常老的问题(5年前),与我的问题无关。我的问题是关于在主表/模型上使用作为关键字。可能是@Fawzan的重复我看到了,这是一个非常老的问题(5年前),与我的问题无关。我的问题是关于在主表/模型上使用as关键字。我从方法中知道这一点,但我不认为它能和雄辩的一起工作,谢谢!我从方法上知道这一点,但我不认为它会和雄辩的人一起工作,谢谢!