0

what is the best way in your idea to have some partial views with data bound to each partial view. and each time in our views we just call the partial views and don't make data for it each time. creating data and pass it to partial views makes controller action dirty and its a work you do many time.I feel I am repeating my self. I know about laravel composer views but I think its not an appropriate way for this purpose.

5
  • View::share() is probably what you're looking for. It lets you share data across all views. Another approach would be to put the common data into a BaseController and let all necessary controllers extend it. Commented Jan 25, 2015 at 16:41
  • I don't want some data to be available through all my views . consider in my index page I have some block of html each relates to specific data. I want to just call the sub views relates to each block and some place in my code structure the data needed for these html blocks be available and I don't pass data each time to each sub view. Commented Jan 25, 2015 at 16:46
  • 1
    I'm not sure I fully understand your problem, but this is exactly what View::share() does - it makes data available across all views, including the partials, of course. So you don't need to pass data from your parent view to the partial, it will be available there automatically. If you want a specific partial to load its own data, regardless of the parent view, then you shold have a look at view composers and this question: stackoverflow.com/questions/18546910/… Commented Jan 25, 2015 at 16:54
  • thanks now i'm reading laravel view composers source code .I think unlike what I thought view composers is exactly what I need but I want my code to be very clean and as this Tutorial says I need to create a service provider . culttt.com/2014/02/10/using-view-composers-laravel-4 thanks again. I just don't know where to put my service provider file. Commented Jan 25, 2015 at 16:58
  • I found out how to do it ;) Commented Jan 25, 2015 at 17:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.