doulu8537 2016-03-21 10:24
浏览 39

试图获得非对象的属性

Here i have a functionality where after a user register to my site it will redirect to path ('user.show').User can also search for another user in the url.If the user exist ('user.show') will provide the requested user's information.But if user search for an invalid name it will provide the current logged in user( the user who is searching ) information.When i attempt for a invalid user i get the error.The error is in the following line

$info=User::where($indicator,'=', Auth::user()->$indicator)->get()->first();

Show() method in user controller :

public function show($user)
    {
        //
        $indicator=is_numeric($user)?'user_id':'username';
        $info=User::where($indicator,'=',$user)->get()->first();
        if($info){
           echo 'bal';
           $data=array('info'=>$info);
           return View::make('user.show')->with('info',$data);
        }else{
          echo "this user doesn't exist";

          $info=User::where($indicator,'=', Auth::user()->$indicator)->get()->first();

          $data=array('info'=>$info);
          return View::make('user.show')->with('info',$data);
        }
    }
  • 写回答

2条回答 默认 最新

  • dos8244 2016-03-21 10:26
    关注

    Try something like this:

    if(Auth::user()){
        // User is authenticated
        $info = User::where($indicator,'=', Auth::user()->$indicator)->get()->first();
    }else{
        // User is not authenticated
    }
    

    Instead of this:

    $info=User::where($indicator,'=', Auth::user()->$indicator)->get()->first();
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?