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!

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

报告相同问题?