php - How to return multiple views in one function in laravel for same route -


it quite difficult explain question. hope able understand it.

for project have master layout contains header , yield of content.

master.blade.php

 @include('partials.header')     <div class="container-fluid main-con">         @yield('content')         @include('partials.footer')     </div>   

now on main public route raturning method.

web.php

route::get('/', [     'uses' => 'productcontoller@getindex',     'as' => 'product.maincats' ]); 

productcontoller.php

class productcontoller extends controller {      public function getindex(){         $ad_cats = mainaddtype::orderby('title')->get();         return view( 'shop.main-categories-page', ['mediacats' => $ad_cats]);     } } 

now query is, 'main-categories-page' yielding in content section of master. want same data of mainadtype in header also. want return view of header on same function. please if u understand it.

what trying is,

 public function getindex(){         $ad_cats = mainaddtype::orderby('title')->get();         return view( 'shop.main-categories-page', ['mediacats' => $ad_cats]);         return view( 'partials.header', ['mediacats' => $ad_cats]);     } 

but know cant return in way. in advance.

you can access variable in header well. have check see if variable exists don't errors when load other views.

@if(!empty($mediacats))    // awesome stuffs $mediacats @endif 

this way data available when on index page.

if want data available in views, can use laravel view composer. official docs:

view composers callbacks or class methods called when view rendered. if have data want bound view each time view rendered, view composer can organize logic single location

hope helps.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -