To display a variable on a Blade template in Laravel, you need to pass the variable from the controller to the view. In this case, you want to display the three variables created in the allPlans method of the SubscriptionController on the plans.blade.php file.
To do this, you can pass the variables as an array to the view function in the controller method. Here's an example of how you can achieve this:
// SubscriptionController.php
use App\Models\Plan;
class SubscriptionController extends Controller
{
public function allPlans()
{
// Fetch the plans from Stripe
$plans = Plan::all();
// Create the three variables representing the travel packets
$biking = $plans->where('type', 'biking')->first();
$hiking = $plans->where('type', 'hiking')->first();
$swimming = $plans->where('type', 'swimming')->first();
// Pass the variables to the view
return view('plans', compact('biking', 'hiking', 'swimming'));
}
}
In the above code, we fetch the plans from Stripe and create the three variables representing the travel packets. Then, we pass these variables to the plans.blade.php view using the compact function.
Now, in your plans.blade.php file, you can access these variables using the {{ }} syntax. Here's an example:
<!-- plans.blade.php -->
@if ($biking)
<p>Biking Plan: {{ $biking->name }}</p>
@endif
@if ($hiking)
<p>Hiking Plan: {{ $hiking->name }}</p>
@endif
@if ($swimming)
<p>Swimming Plan: {{ $swimming->name }}</p>
@endif
In the above code, we use the @if directive to check if each variable exists before displaying its value. If the variable exists, we display its name using the {{ }} syntax.
Make sure to replace Plan with the actual model class you are using for your plans.
This should solve the issue of the "Undefined variable $biking" error and display the variables on the plans.blade.php file.