samedi 3 juin 2017

Laravel: global variables inside AppServiceProvider boot method don't work on hosted server

On my local environment these global variables work fine, but when I put my project files on hosted server they just don't work.

AppServiceProvider.php:

public function boot()
{
    $parentCategories = Category::where('parent', 1)->where('status', 1)->get();
    $childCategories = Category::where('parent', 0)->where('status', 1)->get();

    View::share([
        'parentCategories' => $parentCategories,
        'childCategories' => $childCategories,
        'errors' => null
    ]);
}

I use these variables in a partial widget that is used on every page.

@if($parentCategories && $childCategories)
<button id="categories-collapse" type="button" class="collapsed" data-toggle="collapse" data-target="#categories-navigation" aria-expanded="false">
    <i class="fa fa-bars" aria-hidden="true"></i>
</button>
<div id="categories-navigation" class="collapse">
    <div class="categories-container">
        <ul class="cf">
            @foreach($parentCategories as $parent)
                <li class="dropdown-trigger">
                    <a href="#"></a>
                    <ul class="dropdown-content">
                        @foreach($childCategories as $child)
                            @if($child->parent_id === $parent->id)
                                <li>
                                    <a href="">
                                         <span>()</span>
                                    </a>
                                </li>
                            @endif
                        @endforeach
                    </ul>
                </li>
            @endforeach
        </ul>
    </div>
</div>
@endif

It creates the category navigation, but everything under this part is empty:

<ul class="dropdown-content">
    @foreach($childCategories as $child)
        @if($child->parent_id === $parent->id)
            <li>
                <a href="">
                     <span>()</span>
                </a>
            </li>
        @endif
    @endforeach
</ul>

So it basically doesn't create any links to categories. It gets the parent categories, but not the child ones so it seems that relations are broken?

Any idea for a fix?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2rDaVVM
via IFTTT

Aucun commentaire:

Enregistrer un commentaire