Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Usman_Shaheen's avatar

How to define a variable in laravel controller?

{!! public $stripe_total_balance; public function index(){

    $total_stripe_amount = Stripe_Deposite::get();

    foreach ($total_stripe_amount as $stripe_balance) {
        $balance = 0;
        

        $total_balance =  $balance + $stripe_balance->amount;






        $this->$stripe_total_balance = ;
        dd();

    } !!}

I have this code i want to add the all stripe deposit record to store in a variable and return with view.

0 likes
3 replies
Tray2's avatar

What do you mean?

$variableName;

$anotherVariableName = 'Value';
Usman_Shaheen's avatar

Can you explain about the variable scope in laravel controller.

i mean how can i define a multiple variable with in controller method for multiple purpose.

Tray2's avatar
Tray2
Best Answer
Level 73

Inside the method you just

$variableName;

If it's a property that is accessible for the whole controller you

protected $variableName;

To access the property you need to use

$this->variableName;

I suggest you take some of the OOP lessons on this site.

Please or to participate in this conversation.