leafx
V2EX  ›  PHP

laravel 关联表软删除怎么玩

  •  
  •   leafx · Nov 30, 2015 · 5132 views
    This topic created in 3999 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
    elvba
    Dec 1, 2015❤️1
    1
    $flight->history()->withTrashed()->get();
    leafx
    leafx
    OP
    Dec 1, 2015
    2
    $this->belongsTo()->withTrashed();
    leafx
    leafx
    OP
    Dec 1, 2015
    3
    @elvba 实际上我想用在关联中 已 GOOGLE 到 谢了
    leafx
    leafx
    OP
    Dec 1, 2015
    4
    CLOSED
    guoer
    guoer
    Dec 1, 2015 via iPhone
    5
    @leafx 建议把解决办法 po 出来 供后人参考
    leafx
    leafx
    OP
    Dec 2, 2015 via Android
    6
    @guoer 在 model 中建立关联时候这样做:$this->belongsTo()->withTrashed();
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1510 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 16:36 · PVG 00:36 · LAX 08:36 · JFK 11:36
    ♥ Do have faith in what you're doing.