2016-11-14 160 views
1

我只是想更新我的數據庫表Time_tracker,但當我嘗試某些東西時,我總是收到錯誤。誰能幫我這個?當前的錯誤是PaypalController.php中的ErrorException第57行: 試圖獲取非對象的屬性Laravel 5.2更新數據庫表

這是代碼。

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

您試圖從一個整數(在$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_idPaypalController類。不要忘記全部更換。

希望得到這個幫助!

+0

是的,它的工作原理!非常感謝! – Ace