dongya767979565 2014-02-19 18:00
浏览 38
已采纳

Laravel Parent被软删除,孩子仍然试图显示导致错误?

In Laravel 4 I am having trouble calling a Related model when the Parent model is Soft Deleted...

In my Controller I have this which gets a Campaign record....

$campaign = Campaign::find($id);

In my View for this controller method, I call a related model like this...

echo $campaign->user->profile->full_name;

User is related to Camapign and Profile is related to User

My problem is, if a user is Soft Deleted, when I call echo $campaign->user->profile->full_name;

I get...

ErrorException  
Trying to get property of non-object (View: app/views/campaign/mapView.blade.php)

What I would like to do is instead show an error message that this users campaign is disabled/deleted since the User is soft deleted.

  • 写回答

1条回答 默认 最新

  • douchixu3686 2014-02-19 18:52
    关注

    You can detect if a user has been soft deleted and do something like showing a message or redirect the application

    if ($campaign->user->trashed())
    {
        //show error message or redirect the app with something like Session::flash('error', 'There was an error campaign is disabled ');
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输