简体   繁体   English

我得到“ErrorException(E_NOTICE)试图获取非对象的属性”试图运行一个cron作业脚本

[英]Am getting “ErrorException (E_NOTICE) Trying to get property of non-object” trying to run a cron job script

I'm setting up a new website, i have this cron job script to automatically update all investment 我正在建立一个新的网站,我有这个cron作业脚本来自动更新所有投资

Error seems to be coming from http controller (line: $rLog['amount'] = round(($rep->invest->amount * $rep->invest->plan->percent) / 100,$basic->deci); ). 错误似乎来自http控制器(行: $rLog['amount'] = round(($rep->invest->amount * $rep->invest->plan->percent) / 100,$basic->deci); )。

But i have no idea how to fix it because am totally new to laravel 但我不知道如何修复它,因为我对laravel来说是全新的

  if ($basic->repeat_status == 1){

            $repeats = Repeat::whereStatus(0)->get();
            foreach ($repeats as $rep){
                if ($rep->repeat_time < Carbon::now()){

                    $rLog['user_id'] = $rep->user_id;
                    $rLog['trx_id'] = strtoupper(Str::random(20));
                    $rLog['investment_id'] = $rep->investment_id;
                    $rLog['made_time'] = Carbon::now();
                    $rLog['amount'] = round(($rep->invest->amount * $rep->invest->plan->percent) / 100,$basic->deci);
                    RepeatLog::create($rLog);

                    $rep->total_repeat = $rep->total_repeat + 1;
                    $rep->made_time = Carbon::now();
                    $rep->repeat_time = Carbon::parse()->addHours($rep->invest->plan->compound->compound);
                    if ($rep->total_repeat == $rep->invest->plan->time){
                        $rep->status = 1;
                        $inv = Investment::findOrFail($rep->investment_id);
                        $inv->status = 1;
                        $inv->save();
                    }

                    $rep->save();

I expect the cron job script to run and result should be an update in the original investment by user 我希望cron作业脚本能够运行,结果应该是用户原始投资的更新

I don't think that exception message relate to the cron-job work, It seems to be you have a null property for your object. 我不认为异常消息与cron-job工作有关,似乎你的对象有一个null属性。 check and log the value of $rep->invest if that is null then check the value of $rep->invest->plan to find out your problem. 检查并记录$ rep-> invest的值,如果为null,则检查$ rep-> invest-> plan的值以找出问题所在。

I think one of those things could be null. 我认为其中一件事可能是空的。 then after fix them, you may have other problem related to cron-job but it's different story. 然后在修复它们之后,你可能还有其他与cron-job相关的问题,但这是不同的故事。 good lucks. 祝你好运。

you can try $reptime['invest'] ect... 你可以尝试$ reptime ['invest']等...

But to turn it in to an object use this code : 但要将其转换为对象,请使用以下代码:

json_encode($rep)

because $rep is Problely an array. 因为$ rep是一个有问题的数组。

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM