V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
leafx
V2EX  ›  PHP

laravel 关联表软删除怎么玩

  •  
  •   leafx · 2015-11-30 23:57:03 +08:00 · 3954 次点击
    这是一个创建于 3068 天前的主题,其中的信息可能已经有所发展或是发生改变。

    a 表 软删除
    b 表 关联 a 表

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

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

    没睡的小伙伴 求解~

    6 条回复    2015-12-02 21:32:17 +08:00
    elvba
        1
    elvba  
       2015-12-01 00:01:43 +08:00   ❤️ 1
    $flight->history()->withTrashed()->get();
    leafx
        2
    leafx  
    OP
       2015-12-01 00:01:49 +08:00
    $this->belongsTo()->withTrashed();
    leafx
        3
    leafx  
    OP
       2015-12-01 00:02:44 +08:00
    @elvba 实际上我想用在关联中 已 GOOGLE 到 谢了
    leafx
        4
    leafx  
    OP
       2015-12-01 00:02:50 +08:00
    CLOSED
    guoer
        5
    guoer  
       2015-12-01 08:55:36 +08:00 via iPhone
    @leafx 建议把解决办法 po 出来 供后人参考
    leafx
        6
    leafx  
    OP
       2015-12-02 21:32:17 +08:00 via Android
    @guoer 在 model 中建立关联时候这样做:$this->belongsTo()->withTrashed();
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4503 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 05:33 · PVG 13:33 · LAX 22:33 · JFK 01:33
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.