I can't get value variable in a method, after use this value to another method in one class PHP Laravel.
public function paymentCourse(Request $request)
{
$idCourse = $request->input('idcourse');
$CoursePrice = Course::where('id', $idCourse)->first();
if(Auth::user()->palate) {
if(Auth::user()->palate->is_palate == 1) {
// this value I want to transfer method getTransactionAmount()
$currentPrice = $CoursePrice->price_palate;
}
} else {
// this value I want to transfer method getTransactionAmount()
$currentPrice = $CoursePrice->price;
}
return view('pages.payment-course', compact('currentPrice'));
}
public function getTransactionAmount($type) {
switch ($type) {
case 'palate':
return 11645;
break;
case 'course':
return 15000; // I get value method paymentCourse() $currentPrice.
break;
case 'course_sale':
return 12000; // I get value method paymentCourse() $currentPrice.
break;
default:
throw new \Exception('Wrong transaction type');
}
}
This is my solution, thank you for help.
public function paymentCourse(Request $request)
{
$idCourse = $request->input('idcourse');
$CoursePrice = Course::where('id', $idCourse)->first();
if(Auth::user()->palate) {
if(Auth::user()->palate->is_palate == 1) {
$currentPrice = $CoursePrice->price_palate;
\Session::put('currentPrice', $currentPrice);
}
} else {
$currentPrice = $CoursePrice->price;
\Session::put('currentPrice', $currentPrice);
}
return view('pages.payment-course', compact('currentPrice'));
}
private function getTransactionAmount($type) {
$currentPrice = \Session::get('currentPrice');
switch ($type) {
case 'palate':
return 11645;
break;
case 'course':
return $currentPrice;
break;
case 'course_sale':
return $currentPrice;
break;
default:
throw new \Exception('Wrong transaction type');
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.