Laravel 5.2更新数据库表

时间:2016-11-14 01:46:48

标签: php mysql database laravel laravel-5.2

我只是想更新我的数据库表Time_tracker,但是当我尝试某些东西时我一直都会收到错误。谁能帮我这个? PaypalController.php第57行中的当前错误是ErrorException: 试图获得非对象的属性

这是代码。

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 个答案:

答案 0 :(得分:1)

您尝试从整数(user_id)访问$user_id属性:

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

只需将$user_id->user_id部分替换为$user_id即可。 $user_id已经是已登录用户的ID。所以你的代码应该是这样的:

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

我在$user_id->user_id课程中发现了三次PaypalController次。不要忘记更换所有这些。

希望这有帮助!