Answer the question
In order to leave comments, you need to log in
How to pass a variable to the master template?
I can’t find an answer anywhere, how to pass a variable to the mater template, I have a shopping cart, I make a variable to display products, on the product page, I display this variable, since the controller calls the model and searches for a variable, but how to pass this variable in the master template and so that all this is displayed on any page, and does not give an error about a variable not found? I try through AppServiceProvider.php
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\View;
use App\Models\Order;
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
$orderId = session('orderId');
$order = Order::find($orderId);
View::share('order', $order);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question