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 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘