我只是想更新我的数据库表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');
}
}
答案 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
次。不要忘记更换所有这些。
希望这有帮助!