如何在PHP类中重新定义变量值和使用值到其他方法?

时间:2018-02-17 06:40:29

标签: php laravel

在将这个值用于PHP Laravel类中的另一个方法之后,我无法在方法中获取值变量。

from hypothesis import given, strategies as st, settings, example

def power_of(num,power):
    if power == 0:
        return 1
    elif power == 1:
        return num
    elif power % 2 != 0:
        return num * power_of(num*num, power // 2)
    else:
        return power_of(num*num, power // 2)

@given(st.integers(min_value=0), st.integers(min_value=0))
@example(2, 6)
def test_power_of(i, j):
    assert power_of(i, j) == i**j

1 个答案:

答案 0 :(得分:0)

这是我的解决方案,谢谢你的帮助。

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');
    }

}