Problems with tp5 Association query

Soft deletion is defined in

tp5 model, and
in defining association

$order = Order::get(10);
$order->user //


//
public function user (){
    return $this-hasOne("user","id","user_id");
}

users queried in this way will not be displayed if the delete_time in the deleted datasheet field is not null.

how to make the association method query all data, including soft deleted data

the following way of writing doesn"t work. Or can I only write related queries by myself?

public function user (){
    return $this-hasOne("user","id","user_id")->withTrashed();
}
Jul.14,2021

try preloading queries using with closures? The one below.

/**
 * 
 */
class Order {
    public function user (){
    return $this-hasOne('user','id','user_id');
}

/**
 * 
 */
class User {

}
// user
$order = Order::get(10)->with(['user'=>function($q){$q->withTrashed();}]);
// user
$user = $order->user;
Menu