leafx
V2EX  ›  PHP

laravel 关联表软删除怎么玩

  •  
  •   leafx · Nov 30, 2015 · 4799 views
    This topic created in 3841 days ago, the information mentioned may be changed or developed.

    a 表 软删除
    b 表 关联 a 表

    那么问题来了,关系已建立,我想通过 b 表找到 a 这个对象

    预期的值是这样子的 $b->a->name , 不想多次去查

    没睡的小伙伴 求解~

    6 replies    2015-12-02 21:32:17 +08:00
    elvba
        1
    elvba  
       Dec 1, 2015   ❤️ 1
    $flight->history()->withTrashed()->get();
    leafx
        2
    leafx  
    OP
       Dec 1, 2015
    $this->belongsTo()->withTrashed();
    leafx
        3
    leafx  
    OP
       Dec 1, 2015
    @elvba 实际上我想用在关联中 已 GOOGLE 到 谢了
    leafx
        4
    leafx  
    OP
       Dec 1, 2015
    CLOSED
    guoer
        5
    guoer  
       Dec 1, 2015 via iPhone
    @leafx 建议把解决办法 po 出来 供后人参考
    leafx
        6
    leafx  
    OP
       Dec 2, 2015 via Android
    @guoer 在 model 中建立关联时候这样做:$this->belongsTo()->withTrashed();
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2898 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 05:30 · PVG 13:30 · LAX 22:30 · JFK 01:30
    ♥ Do have faith in what you're doing.