dpaal28266 2016-11-14 01:46
浏览 40
已采纳

Laravel 5.2更新数据库表

I just want to update my database table Time_tracker, but i keep getting error when i attempt something. Can anyone help me with this? the current error is ErrorException in PaypalController.php line 57: Trying to get property of non-object

this is the code.

PaypalController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\Input;

use Illuminate\Support\Facades\Validator;

use Illuminate\Support\Facades\Redirect;

use Illuminate\Support\Facades\Request;

use Illuminate\Support\Facades\Session;

use Illuminate\Support\Facades\Auth;

use Illuminate\Support\Facades\DB;

use Illuminate\Mail\Mailer;

use App\Maintenance;

use App\Time_tracker;


class PaypalController extends Controller {

 /**
 * Create a new controller instance.
 *
 * @return void
 */
public function __construct()
{
    $this->middleware('auth');
}

/**
 * Show the application dashboard.
 *
 * @return \Illuminate\Http\Response
 */

 public function index() {

 return view('paypal'); 

 }

 public function success() {
 $price = \Session::get('value_price');
 $value = $price;
 if($value == '465'){

     $user_id = Auth::user()->id;

     $Totalpurchase = DB::table('time_tracker')->where('user_id', $user_id->user_id )->sum('purshase_time');         

         $purchase = $Totalpurchase + 15;

         DB::table('users')
             ->where('user_id', $user_id)
             ->update(['status' => 'paid',
                       'purshase_time' => $purchase_time
             ]);

 }elseif($value == '700'){

     $user_id = Auth::user()->id;

     $Totalpurchase = DB::table('time_tracker')->where('user_id', $user_id->user_id )->sum('purshase_time');

         $purchase = $Totalpurchase + 25;

         DB::table('users')
             ->where('user_id', $user_id)
             ->update(['status' => 'paid',
                       'purshase_time' => $purchase_time
             ]);


 }elseif($value == '1300'){

     $user_id = Auth::user()->id;

     $Totalpurchase = DB::table('time_tracker')->where('user_id', $user_id->user_id )->sum('purshase_time');

         $purchase = $Totalpurchase + 50;

         DB::table('users')
             ->where('user_id', $user_id)
             ->update(['status' => 'paid',
                       'purshase_time' => $purchase_time
             ]);

 }


 return view('success');    

 }


 public function failed() {

 return view('failed'); 

 }


 }
  • 写回答

1条回答 默认 最新

  • duan0403788996 2016-11-14 02:12
    关注

    You tried to access the user_id property from an integer (the $user_id):

    $Totalpurchase = DB::table('time_tracker')->where('user_id', $user_id->user_id )->sum('purshase_time');
    

    Just replace the $user_id->user_id part with $user_id. The $user_id is already an id of logged user. So your code should look like this instead:

    $Totalpurchase = DB::table('time_tracker')->where('user_id', $user_id)->sum('purshase_time');
    

    I found three occurrences of $user_id->user_id on your PaypalController class. Don't forget to replace all of them.

    Hope this help!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看