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

Bono's avatar
Level 1

Can't fetch plan from stripe and show them to user

Hello, I am using Laravel 10 for a university project. i would fetch my Plan model (using his controller called subscriptioncontroller.php) from stripe and show t(hree variables created in the controller in the method "allPlans" which represent 3 type of travel pkts i would use for my application) to user (through my plans.blade.php). Earlier when i open on http://127.0.0.1:8000 and search "/plans" in the seach bar i encountered error "Undefined variable $biking" highlighted on my istruction "@if($biking)". I show my files below:

SubscriptionController.php (i use both Plan and ModelsPlan)

0 likes
4 replies
LaryAI's avatar
Level 58

Based on the information provided, it seems that the error "Undefined variable $biking" is occurring because the variable $biking is not being passed to the plans.blade.php view. To fix this, you need to make sure that the variable is passed to the view correctly.

Here's a possible solution:

In your SubscriptionController.php file, make sure that you are passing the $biking variable to the plans.blade.php view. You can do this by modifying the allPlans method as follows:

use App\Models\Plan;

public function allPlans()
{
    $biking = Plan::where('type', 'biking')->get();
    $hiking = Plan::where('type', 'hiking')->get();
    $swimming = Plan::where('type', 'swimming')->get();

    return view('plans', compact('biking', 'hiking', 'swimming'));
}

Make sure to import the Plan model at the top of the file.

Then, in your plans.blade.php file, you can access the $biking, $hiking, and $swimming variables using the @if directive like this:

@if($biking)
    <!-- Display biking plans -->
@endif

@if($hiking)
    <!-- Display hiking plans -->
@endif

@if($swimming)
    <!-- Display swimming plans -->
@endif

Remember to replace the <!-- Display ... --> sections with your actual HTML code.

This should resolve the "Undefined variable $biking" error and allow you to display the plans to the user.

Bono's avatar
Level 1

I did how you write me but it didn't change, what can i look at?

Snapey's avatar

please show your code

paste it with three backticks ``` on their own line before and after your code block

Please or to participate in this conversation.