简体   繁体   中英

Using AS Keyword in Laravel Eloquent Join Query In Main Model

I want to use AS keyword in Laravel Eloquent Model like that:

Here my sample query:

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

Expected usage u.id instead of users.id on joins with main table/model

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

Is there such a feature, is it possible?

use from method in eloquent like that

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

see this query eloquent method here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM