The issue might be related to the way you are fetching the plans from Stripe. Make sure you have properly set up your Stripe API credentials in your Laravel application.
Here's a possible solution:
- First, make sure you have installed the Stripe PHP library by running the following command in your terminal:
composer require stripe/stripe-php
- In your
SubscriptionController, import thePlanclass from the Stripe library at the top of the file:
use Stripe\Plan;
- In the
allPlansmethod, you need to initialize the Stripe library by setting your API key. You can do this in the constructor of your controller or in theallPlansmethod itself. Here's an example of setting the API key in theallPlansmethod:
public function allPlans()
{
// Set your Stripe API key
\Stripe\Stripe::setApiKey('your_stripe_api_key');
// Fetch the plans from Stripe
$plans = Plan::all();
// Create the three variables representing the travel packets
$biking = $plans->data->where('metadata.type', 'biking')->first();
$hiking = $plans->data->where('metadata.type', 'hiking')->first();
$walking = $plans->data->where('metadata.type', 'walking')->first();
// Pass the variables to the view
return view('stripe.plans', compact('biking', 'hiking', 'walking'));
}
Make sure to replace 'your_stripe_api_key' with your actual Stripe API key.
Note that the Plan::all() method returns a collection of plans. You can access the plans using the data property of the returned object.
Also, in your code, you are using the type field to filter the plans. If the type field is stored as metadata in your Stripe plans, you need to access it using metadata.type as shown in the code above.
Remember to replace 'stripe.plans' with the actual view name you want to render.
Let me know if this helps!