Faran Khan
Faran Khan

Reputation: 1565

Passing back the variable from include blade in laravel

I am using laravel 5.3 and having some trouble getting back the variable from included blade. The problem is:

I have two blade:

1) main.blade.php 2) product.blade.php ( included in main.blade.php )

Now I am defining and calculating $fee in product.blade.php and the total is calculated in main.blade.php

I can see the $fee calculating properly in product blade. But when I add $fee to total, It shows me Undefined variable.

One solution is to define it global in main.blade.php and product.blade.php , But I dont want to use that approach.

Can someone help me with this please?

Upvotes: 0

Views: 1009

Answers (1)

Mohamed Akram
Mohamed Akram

Reputation: 2117

You have to use view composer class for that, this article may be help full for you

https://scotch.io/tutorials/sharing-data-between-views-using-laravel-view-composers

Upvotes: 1

Related Questions