hackroot's avatar

laracom ecommerce, routes and menus

Hi i just installed laracom ecommerce (a laravel ecommerce web application), However i can't get the menu to appear in the frontend. here is my project https://www.kesselacosmetics.com. I'm told that i am suppose to pass a category route at to the frontend but i am quite new here. Any assistance is very much appreciated. Thanks in Advanced

0 likes
32 replies
automica's avatar

@hackroot does Laracom ship with any documentation or setup instructions?

I had a look on GitHub page for the package and didn’t see a very comprehensive install guide.

Do you have anything you can share?

What bit of the menu are you trying to add? I can see on your site link and that looks like the demo version.

hackroot's avatar

Hi, i searched every where and this is the only documentation I found https://shop.laracom.net/docs/1.4.6/overview, however I came across this instructions this instruction on https://gitter.im/larac0m/Lobby.

***Dalkyel @Dalkyel Mar 12 2019 01:07 Hello... I got a question... does the project have a sidebar category? if it does how can I make it visible? Thanks

Jeff Simons Decena @jsdecena Mar 12 2019 02:36 @Dalkyel you can do that. Just pass the categories from the controller to the view

Dalkyel @Dalkyel Mar 12 2019 14:09 thanks Jeff... it worked, now the problem is I don't know how to render de side bar.***

unfortunately the the above is about the sidebar. However I want to add both the main menu and sidebar too.

I can send my code if required.

automica's avatar

@hackroot I just installed and it looks like theres no default menu, but it is easy to add.

You need to modify 2 files.

in your HomeController (in App\Http\Controllers\Front)

modify the bottom of index method to the following:

        $categories = $this->categoryRepo->listCategories();

        return view('front.index', compact('cat1', 'cat2','categories'));

then in your index page (resources/views/front/index.blade.php)

add the following:

    @foreach($categories as $category)
        @if($loop->first)
            <ul>
                @endif
                <li><a href="{{ route('front.category.slug', $category->slug) }}">{{$category->name}}</a></li>
                @if($loop->last)
            </ul>
        @endif
    @endforeach

This provides a basic list of categories with a link to the category page.

I'm not sure what you are describing as sidebar. if this is still relevant please explain further.

hackroot's avatar

Hi @automica I just did the changes but I am getting this error;

ErrorException (E_NOTICE) compact(): Undefined variable: categories

C:\laragon\www\laracom\app\Http\Controllers\Front\HomeController.php private $categoryRepo;

/**
 * HomeController constructor.
 * @param CategoryRepositoryInterface $categoryRepository
 */
public function __construct(CategoryRepositoryInterface $categoryRepository)
{
    $this->categoryRepo = $categoryRepository;
}

/**
 * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
 */
public function index()
{
    $cat1 = $this->categoryRepo->findCategoryById(2);
    $cat2 = $this->categoryRepo->findCategoryById(3);

    return view('front.index', compact('cat1', 'cat2','categories'));
}

}

Arguments "compact(): Undefined variable: categories"

any help please

hackroot's avatar

@automica Hi Thanks a lot the menu is now showing at the frontend however it the stylesheets aren't affect it also, by sidebar; I am referring to the sidebars on the left side of the category pages. it is also a call to all the categories. Thanks

automica's avatar

@hackroot the categories list in the sidebar of a category page lists all the sub categories of that category.

if you want to get an item to display there, create a new category and set its parent category and it will appear in the sidebar of that parent.

hackroot's avatar

Hello @automica , Thanks for your assistance so far anyway I've tried doing as you stated above but nothing happens. I also noticed that the code for the menus has already been implemented but they aren't working either.

Below are the file in relation to the pro;

../views/layouts/front/category-nav.blade.php

<ul class="list-unstyled list-inline nav navbar-nav">
    @foreach($categories as $category)
        <li>
            @if($category->children()->count() > 0)
                @include('layouts.front.category-sub', ['subs' => $category->children])
            @else
                <a @if(request()->segment(2) == $category->slug) class="active" @endif href="{{route('front.category.slug', $category->slug)}}">{{$category->name}} </a>
            @endif
        </li>
    @endforeach
</ul>

../views/layouts/front/category-sidebar-sub.blade.php

@foreach($subs as $sub)
    <a href="{{ route('front.category.slug', $category->slug) }}">{{ $category->name }}</a>
    <ul class="list-unstyled sidebar-category-sub">
        <li @if(request()->segment(2) == $sub->slug) class="active" @endif ><a href="{{ route('front.category.slug', $sub->slug) }}">{{ $sub->name }}</a></li>
    </ul>
@endforeach

views/layouts/front/category-sub.blade.php

<div class="dropdown">
    <a @if(request()->segment(2) == $category->slug) class="active" @endif href="{{route('front.category.slug', $category->slug)}}" class="dropdown-toggle" id="{{$category->slug}}" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">{{$category->name}} <span class="caret"></span></a>
    <ul class="dropdown-menu" aria-labelledby="{{$category->slug}}">
        @foreach($subs as $sub)
            <li><a href="{{route('front.category.slug', $sub->slug)}}">{{$sub->name}}</a></li>
        @endforeach
    </ul>
</div>

views/layouts/front/header-cart.blade.php

<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
    @include('layouts.front.category-nav')
    <ul class="nav navbar-nav navbar-right">
        @if(auth()->check())
            <li class="visible-xs"><a href="{{ route('accounts', ['tab' => 'profile']) }}"><i class="fa fa-home"></i> My Account</a></li>
            <li class="visible-xs"><a href="{{ route('logout') }}"><i class="fa fa-sign-out"></i> Logout</a></li>
        @else
            <li class="visible-xs"><a href="{{ route('login') }}"> <i class="fa fa-lock"></i> Login</a></li>
            <li class="visible-xs"><a href="{{ route('register') }}"> <i class="fa fa-sign-in"></i> Register</a></li>
        @endif
        <li id="cart" class="menubar-cart visible-xs">
            <a href="{{ route('cart.index') }}" title="View Cart" class="awemenu-icon menu-shopping-cart">
                <i class="fa fa-shopping-cart" aria-hidden="true"></i>
                <span class="cart-number">{{ $cartCount }}</span>
            </a>
        </li>
        <li>
            <!-- search form -->
            <form action="{{route('search.product')}}" method="GET" class="form-inline" style="margin: 15px 0 0;">
                <div class="input-group">
                    <input type="text" name="q" class="form-control" placeholder="Search..." value="{!! request()->input('q') !!}">
                    <span class="input-group-btn">
                        <button type="submit" id="search-btn" class="btn btn-flat"><i class="fa fa-search"></i> Search</button>
                    </span>
                </div>
            </form>
            <!-- /.search form -->
        </li>
    </ul>
</div><!-- /.navbar-collapse -->

../views/layouts/front/app.blade.php

<!DOCTYPE html>
<html lang="en">
<head>
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id={{ env('GOOGLE_ANALYTICS') }}"></script>
    <script>
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());

        gtag('config', '{{ env('GOOGLE_ANALYTICS') }}');
    </script>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>{{ config('app.name') }}</title>
    <title>Kessela Cosmetics</title>
    <meta name="description" content="A Ghanaian Online Cosmetics Shop">
    <meta name="tags" content="modern, e-commerce, free, kessela, shopping, responsive, fast, Mtn, Money, storefront">
    <meta name="author" content="Tom Collins">
    <link href="{{ asset('css/style.min.css') }}" rel="stylesheet">

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="{{ asset('https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js')}}"></script>
    <script src="{{ asset('https://oss.maxcdn.com/respond/1.4.2/respond.min.js')}}"></script>
    <![endif]-->
    <link rel="apple-touch-icon" sizes="57x57" href="{{ asset('favicons/apple-icon-57x57.png')}}">
    <link rel="apple-touch-icon" sizes="60x60" href="{{ asset('favicons/apple-icon-60x60.png')}}">
    <link rel="apple-touch-icon" sizes="72x72" href="{{ asset('favicons/apple-icon-72x72.png')}}">
    <link rel="apple-touch-icon" sizes="76x76" href="{{ asset('favicons/apple-icon-76x76.png')}}">
    <link rel="apple-touch-icon" sizes="114x114" href="{{ asset('favicons/apple-icon-114x114.png')}}">
    <link rel="apple-touch-icon" sizes="120x120" href="{{ asset('favicons/apple-icon-120x120.png')}}">
    <link rel="apple-touch-icon" sizes="144x144" href="{{ asset('favicons/apple-icon-144x144.png')}}">
    <link rel="apple-touch-icon" sizes="152x152" href="{{ asset('favicons/apple-icon-152x152.png')}}">
    <link rel="apple-touch-icon" sizes="180x180" href="{{ asset('favicons/apple-icon-180x180.png')}}">
    <link rel="icon" type="image/png" sizes="192x192"  href="{{ asset('favicons/android-icon-192x192.png')}}">
    <link rel="icon" type="image/png" sizes="32x32" href="{{ asset('favicons/favicon-32x32.png')}}">
    <link rel="icon" type="image/png" sizes="96x96" href="{{ asset('favicons/favicon-96x96.png')}}">
    <link rel="icon" type="image/png" sizes="16x16" href="{{ asset('favicons/favicon-16x16.png')}}">
    <link rel="manifest" href="{{ asset('favicons/manifest.json')}}">
    <meta name="msapplication-TileColor" content="#ffffff">
    <meta name="msapplication-TileImage" content="{{ asset('favicons/ms-icon-144x144.png')}}">
    <meta name="theme-color" content="#ffffff">
    @yield('css')
    <meta property="og:url" content="{{ request()->url() }}"/>
    @yield('og')
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="{{ asset('https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js') }}"></script>
</head>
<body>
<noscript>
    <p class="alert alert-danger">
        You need to turn on your javascript. Some functionality will not work if this is disabled.
        <a href="https://www.enable-javascript.com/" target="_blank">Read more</a>
    </p>
</noscript>
<section>
    <div class="hidden-xs">
        <div class="container">
            <div class="clearfix"></div>
            <div class="pull-right">
                <ul class="nav navbar-nav navbar-right">
                    @if(auth()->check())
                        <li><a href="{{ route('accounts', ['tab' => 'profile']) }}"><i class="fa fa-home"></i> My Account</a></li>
                        <li><a href="{{ route('logout') }}"><i class="fa fa-sign-out"></i> Logout</a></li>
                    @else
                        <li><a href="{{ route('login') }}"> <i class="fa fa-lock"></i> Login</a></li>
                        <li><a href="{{ route('register') }}"> <i class="fa fa-sign-in"></i> Register</a></li>
                    @endif
                    <li id="cart" class="menubar-cart">
                        <a href="{{ route('cart.index') }}" title="View Cart" class="awemenu-icon menu-shopping-cart">
                            <i class="fa fa-shopping-cart" aria-hidden="true"></i>
                            <span class="cart-number">{{ $cartCount }}</span>
                        </a>
                    </li>
                </ul>
            </div>
        </div>
    </div>
    <header id="header-section">
        <nav class="navbar navbar-default">
            <div class="container">
                <!-- Brand and toggle get grouped for better mobile display -->
                <div class="navbar-header col-md-2">
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="{{ route('home') }}">{{ config('app.name') }}</a>
                </div>
                <div class="col-md-10">
                    @include('layouts.front.header-cart')
                </div>
            </div>
        </nav>
    </header>
</section>
@yield('content')

@include('layouts.front.footer')

<script src="{{ asset('js/front.min.js') }}"></script>
<script src="{{ asset('js/custom.js') }}"></script>
@yield('js')
</body>
</html>

../views/front/index.blade.php

@extends('layouts.front.app')

@section('og')
    <meta property="og:type" content="home"/>
    <meta property="og:title" content="{{ config('app.name') }}"/>
    <meta property="og:description" content="{{ config('app.name') }}"/>
@endsection

@section('content')
    @include('layouts.front.home-slider')
    @if($cat1->products->isNotEmpty())
        <section class="new-product t100 home">
            <div class="container">
                <div class="section-title b50">
                    <h2>{{ $cat1->name }}</h2>
                </div>
                @include('front.products.product-list', ['products' => $cat1->products->where('status', 1)])
                <div id="browse-all-btn"> <a class="btn btn-default browse-all-btn" href="{{ route('front.category.slug', $cat1->slug) }}" role="button">browse all items</a></div>
            </div>
        </section>
    @endif
    <hr>
    @if($cat2->products->isNotEmpty())
        <div class="container">
            <div class="section-title b100">
                <h2>{{ $cat2->name }}</h2>
            </div>
            @include('front.products.product-list', ['products' => $cat2->products->where('status', 1)])
            <div id="browse-all-btn"> <a class="btn btn-default browse-all-btn" href="{{ route('front.category.slug', $cat2->slug) }}" role="button">browse all items</a></div>
        </div>
    @endif
    <hr />
    <!--@include('mailchimp::mailchimp')-->
@endsection

../views/front/categories/category.blade.php

@extends('layouts.front.app')

@section('og')
    <meta property="og:type" content="category"/>
    <meta property="og:title" content="{{ $category->name }}"/>
    <meta property="og:description" content="{{ $category->description }}"/>
    @if(!is_null($category->cover))
        <meta property="og:image" content="{{ asset("storage/$category->cover") }}"/>
    @endif
@endsection

@section('content')
    <div class="container">
        <hr>
        <div class="row">
            <div class="category-top col-md-12">
                <h2>{{ $category->name }}</h2>
                {!! $category->description !!}
            </div>
        </div>
        <hr>
        <div class="col-md-3">
            @include('front.categories.sidebar-category')
        </div>
        <div class="col-md-9">
            <div class="row">
                <div class="category-image">
                    @if(isset($category->cover))
                        <img src="{{ asset("storage/$category->cover") }}" alt="{{ $category->name }}" class="img-responsive" />
                    @else
                        <img src="https://placehold.it/1200x200" alt="{{ $category->cover }}" class="img-responsive" />
                    @endif
                </div>
            </div>
            <hr>
            <div class="row">
                @include('front.products.product-list', ['products' => $products])
            </div>
        </div>
    </div>
@endsection

../views/front/categories/sidebar-category.blade.php

<ul class="nav sidebar-menu">
    @foreach($categories as $category)
        @if($category->children()->count() > 0)
            <li>@include('layouts.front.category-sidebar-sub', ['subs' => $category->children])</li>
        @else
            <li @if(request()->segment(2) == $category->slug) class="active" @endif><a href="{{ route('front.category.slug', $category->slug) }}">{{ $category->name }}</a></li>
        @endif
    @endforeach
</ul>

../app/http/controllers/front/HomeController.php

<?php

namespace App\Http\Controllers\Front;

use App\Shop\Categories\Repositories\Interfaces\CategoryRepositoryInterface;

class HomeController
{
    /**
     * @var CategoryRepositoryInterface
     */
    private $categoryRepo;

    /**
     * HomeController constructor.
     * @param CategoryRepositoryInterface $categoryRepository
     */
    public function __construct(CategoryRepositoryInterface $categoryRepository)
    {
        $this->categoryRepo = $categoryRepository;
    }

    /**
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function index()
    {
        $cat1 = $this->categoryRepo->findCategoryById(2);
        $cat2 = $this->categoryRepo->findCategoryById(3);

        return view('front.index', compact('cat1', 'cat2'));
    }
}

../app/http/controllers/front/CategoryController.php

<?php

namespace App\Http\Controllers\Front;

use App\Shop\Categories\Repositories\CategoryRepository;
use App\Shop\Categories\Repositories\Interfaces\CategoryRepositoryInterface;
use App\Http\Controllers\Controller;

class CategoryController extends Controller
{
    /**
     * @var CategoryRepositoryInterface
     */
    private $categoryRepo;

    /**
     * CategoryController constructor.
     *
     * @param CategoryRepositoryInterface $categoryRepository
     */
    public function __construct(CategoryRepositoryInterface $categoryRepository)
    {
        $this->categoryRepo = $categoryRepository;
    }

    /**
     * Find the category via the slug
     *
     * @param string $slug
     * @return \App\Shop\Categories\Category
     */
    public function getCategory(string $slug)
    {
        $category = $this->categoryRepo->findCategoryBySlug(['slug' => $slug]);

        $repo = new CategoryRepository($category);

        $products = $repo->findProducts()->where('status', 1)->all();

        return view('front.categories.category', [
            'category' => $category,
            'products' => $repo->paginateArrayResults($products, 20)
        ]);
    }
}

../app/Providers/GlobalTemplateServiceProvider.php

<?php

namespace App\Providers;

use App\Shop\Carts\Repositories\CartRepository;
use App\Shop\Carts\ShoppingCart;
use App\Shop\Categories\Category;
use App\Shop\Categories\Repositories\CategoryRepository;
use App\Shop\Employees\Employee;
use App\Shop\Employees\Repositories\EmployeeRepository;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\ServiceProvider;

/**
 * Class GlobalTemplateServiceProvider
 * @package App\Providers
 * @codeCoverageIgnore
 */
class GlobalTemplateServiceProvider extends ServiceProvider
{
    /**
     * Register bindings in the container.
     *
     * @return void
     */
    public function boot()
    {
        view()->composer([
            'layouts.admin.app',
            'layouts.admin.sidebar',
            'admin.shared.products'
        ], function ($view) {
            $view->with('admin', Auth::guard('employee')->user());
        });

        view()->composer(['layouts.front.app', 'front.categories.sidebar-category'], function ($view) {
            $view->with('categories', $this->getCategories());
            $view->with('cartCount', $this->getCartCount());
        });

        /**
         * breadcumb
         */
        view()->composer([
            "layouts.admin.app"
        ], function ($view) {
            $breadcumb = [
                ["name" => "Dashboard", "url" => route("admin.dashboard"), "icon" => "fa fa-dashboard"],
            ];
            $paths = request()->segments();
            if (count($paths) > 1) {
                foreach ($paths as $key => $pah) {
                    if ($key == 1)
                        $breadcumb[] = ["name" => ucfirst($pah), "url" => request()->getBaseUrl() . "/" . $paths[0] . "/" . $paths[$key], 'icon' => config("module.admin." . $pah . ".icon")];
                    elseif ($key == 2)
                        $breadcumb[] = ["name" => ucfirst($pah), "url" => request()->getBaseUrl() . "/" . $paths[0] . "/" . $paths[1] . "/" . $paths[$key], 'icon' => config("module.admin." . $pah . ".icon")];
                }
            }
            $view->with(
                [
                    "breadcumbs" => $breadcumb
                ]
            );
        });


        view()->composer(['layouts.front.category-nav'], function ($view) {
            $view->with('categories', $this->getCategories());
        });
    }

    /**
     * Get all the categories
     *
     */
    private function getCategories()
    {
        $categoryRepo = new CategoryRepository(new Category);
        return $categoryRepo->listCategories('name', 'asc', 1)->whereIn('parent_id', [1]);
    }

    /**
     * @return int
     */
    private function getCartCount()
    {
        $cartRepo = new CartRepository(new ShoppingCart);
        return $cartRepo->countItems();
    }

    /**
     * @param Employee $employee
     * @return bool
     */
    private function isAdmin(Employee $employee)
    {
        $employeeRepo = new EmployeeRepository($employee);
        return $employeeRepo->hasRole('admin');
    }
}

So observed the above files and notice that the menu is already imported however I can't find why neither functions are working. Please Assist. @automica, Stay Blessed. Thanks again

automica's avatar

@hackroot I'm genuinely having trouble deciding whether the categories functionality is even working properly in laracom.

Having added some subcategories earlier, I briefly got one to display but cant see why its not displaying correctly, unless there is a caching layer somewhere.

I've noticed that globally there is a list of $categories being defined and passed into all views, so the addition I made to HomeController detailed in an earlier comment shouldn't need to be there.

I think I will clean install and see if I can understand whats going on and perhaps make a PR to the package to fix some of this once I work out whats up.

Sadly that doesn't help you now but if I find anything else I will update this thread.

hackroot's avatar

@automica Okay sir Thanks a lot, I managed to add a simple payment system in laracom hence why i wanna use it. Your assistance will be much appreciated.

automica's avatar

@hackroot I see you are having some success on the Laracom GitHub issues page.

I’ll keep fiddling and hopefully we’ll understand how it works eventually

hackroot's avatar

hello @automica , please did you find any solutions to the menu and category issue? the supporters at the laracom github page are late to respond.

automica's avatar

@hackroot I’ve raised an issue myself on Laracom issue tracker for the categories, as the only way I can see categories displaying is to create them as subcategories and at that point they display for all categories rather than just in the category they are set in.

My user on GitHub is iammikek

1 like
hackroot's avatar

@automica Hello so please using the script you gave me earliar the menu was visible but not styled. I wanted to know if the is a way I can let it replace the current menu options so as to move forward with this current system?

automica's avatar

@hackroot I am working through a ticket on GitHub to improve navigation.

https://github.com/jsdecena/laracom/issues/245

In the meantime, perhaps you can explain how you would expect the top navigation and side menu to display?

Whilst I would like the package owner to explain what it should be currently doing, I would suggest the following:

  1. Top navigation - shows clickable links to top level categories, When you hover over them, you should see drop down of all subcategories and these are clickable.

  2. side navigation. Displays when you enter a category, Shows all child categories right the way up to their parent:

Eg

Top Level Category
- Category 1
-- Category 1 Subcategory 1
-- Category 1 Subcategory 2
-- Category 1 Subcategory 3
- Category 2
-- Category 2 Subcategory 1
-- Category 2 Subcategory 2
-- Category 2 Subcategory 3
- Category 3
-- Category 3 Subcategory 1
-- Category 3 Subcategory 2
-- Category 3 Subcategory 3

the category you are in is highlighted in the menu.

I'm not sure if the side navigation structure is ideal here. It may be also appropriate to just display the category you are on and its siblings and children with a link to go 'up';

eg:

if I am in Category 1 Subcategory 1 then I see

-- Category 1 Subcategory 1
-- Category 1 Subcategory 2
-- Category 1 Subcategory 3
hackroot's avatar

@automica, I totally agree with your suggestion, That's exactly how I will expect the top and side-menu to display. I'm very glad for your assistance.

automica's avatar
automica
Best Answer
Level 54

@hackroot I've made my first version of a fix for this, and have published up to my fork of the laracom project if you want to give it a look.

https://github.com/jsdecena/laracom/compare/master...iammikek:feature/subcategories

Currently, side menu behaves as discussed above. The top menu is a bit simpler just displaying root categories and their next level down.

You'll need to undo the changes I've suggested in the thread earlier but hopefully this update should get you what you are after.

hackroot's avatar

Hi so I followed your fix above and came across the following errors

ErrorException (E_ERROR)
Undefined variable: rootCategories (View: C:\laragon\www\laracom\resources\views\layouts\front\category-nav.blade.php) (View: C:\laragon\www\laracom\resources\views\layouts\front\category-nav.blade.php)
Previous exceptions
Undefined variable: rootCategories (View: C:\laragon\www\laracom\resources\views\layouts\front\category-nav.blade.php) (0)
Undefined variable: rootCategories (0)
ErrorException thrown with message "Undefined variable: rootCategories (View: C:\laragon\www\laracom\resources\views\layouts\front\category-nav.blade.php) (View: C:\laragon\www\laracom\resources\views\layouts\front\category-nav.blade.php)"

Stacktrace:
#65 ErrorException in C:\laragon\www\laracom\storage\framework\views\b3d9023cdec816e7a088eb0630a2731da1490179.php:1
#64 Illuminate\View\Engines\CompilerEngine:handleViewException in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\View\Engines\PhpEngine.php:45
#63 Illuminate\View\Engines\CompilerEngine:handleViewException in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\View\Engines\PhpEngine.php:45
#62 ErrorException in C:\laragon\www\laracom\storage\framework\views\b3d9023cdec816e7a088eb0630a2731da1490179.php:1
#61 Illuminate\Foundation\Bootstrap\HandleExceptions:handleError in C:\laragon\www\laracom\storage\framework\views\b3d9023cdec816e7a088eb0630a2731da1490179.php:1
#60 include in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\View\Engines\PhpEngine.php:43
#59 Illuminate\View\Engines\PhpEngine:evaluatePath in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\View\Engines\CompilerEngine.php:59
#58 Illuminate\View\Engines\CompilerEngine:get in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\View\View.php:142
#57 Illuminate\View\View:getContents in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\View\View.php:125
#56 Illuminate\View\View:renderContents in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\View\View.php:90
#55 Illuminate\View\View:render in C:\laragon\www\laracom\storage\framework\views97dd650a1661e3952c8200e4a3b4e7cf3f6be9.php:6
#54 include in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\View\Engines\PhpEngine.php:43
#53 Illuminate\View\Engines\PhpEngine:evaluatePath in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\View\Engines\CompilerEngine.php:59
#52 Illuminate\View\Engines\CompilerEngine:get in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\View\View.php:142
#51 Illuminate\View\View:getContents in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\View\View.php:125
#50 Illuminate\View\View:renderContents in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\View\View.php:90
#49 Illuminate\View\View:render in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Http\Response.php:42
#48 Illuminate\Http\Response:setContent in C:\laragon\www\laracom\vendor\symfony\http-foundation\Response.php:205
#47 Symfony\Component\HttpFoundation\Response:__construct in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Routing\Router.php:750
#46 Illuminate\Routing\Router:toResponse in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Routing\Router.php:722
#45 Illuminate\Routing\Router:prepareResponse in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Routing\Router.php:682
#44 Illuminate\Routing\Router:Illuminate\Routing\{closure} in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:30
#43 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Routing\Middleware\SubstituteBindings.php:41
#42 Illuminate\Routing\Middleware\SubstituteBindings:handle in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163
#41 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53
#40 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken.php:75
#39 Illuminate\Foundation\Http\Middleware\VerifyCsrfToken:handle in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163
#38 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53
#37 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\View\Middleware\ShareErrorsFromSession.php:49
#36 Illuminate\View\Middleware\ShareErrorsFromSession:handle in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163
#35 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53
#34 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Session\Middleware\StartSession.php:63
#33 Illuminate\Session\Middleware\StartSession:handle in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163
#32 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53
#31 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse.php:37
#30 Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse:handle in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163
#29 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53
#28 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\EncryptCookies.php:66
#27 Illuminate\Cookie\Middleware\EncryptCookies:handle in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163
#26 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53
#25 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:104
#24 Illuminate\Pipeline\Pipeline:then in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Routing\Router.php:684
#23 Illuminate\Routing\Router:runRouteWithinStack in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Routing\Router.php:659
#22 Illuminate\Routing\Router:runRoute in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Routing\Router.php:625
#21 Illuminate\Routing\Router:dispatchToRoute in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Routing\Router.php:614
#20 Illuminate\Routing\Router:dispatch in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php:176
#19 Illuminate\Foundation\Http\Kernel:Illuminate\Foundation\Http\{closure} in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:30
#18 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in C:\laragon\www\laracom\vendor\fideloper\proxy\src\TrustProxies.php:57
#17 Fideloper\Proxy\TrustProxies:handle in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163
#16 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53
#15 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php:31
#14 Illuminate\Foundation\Http\Middleware\TransformsRequest:handle in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163
#13 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53
#12 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php:31
#11 Illuminate\Foundation\Http\Middleware\TransformsRequest:handle in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163
#10 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53
#9 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\ValidatePostSize.php:27
#8 Illuminate\Foundation\Http\Middleware\ValidatePostSize:handle in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163
#7 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53
#6 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode.php:62
#5 Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode:handle in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163
#4 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53
#3 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:104
#2 Illuminate\Pipeline\Pipeline:then in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php:151
#1 Illuminate\Foundation\Http\Kernel:sendRequestThroughRouter in C:\laragon\www\laracom\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php:116
#0 Illuminate\Foundation\Http\Kernel:handle in C:\laragon\www\laracom\public\index.php:53
C:\laragon\www\laracom\storage\framework\views\b3d9023cdec816e7a088eb0630a2731da1490179.php
<?php $__currentLoopData = $rootCategories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $category): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
    <?php if($loop->first): ?>
        <ul class="list-unstyled list-inline nav navbar-nav">
            <?php endif; ?>
            <li>
                <?php if($category->children()->count() > 0): ?>
                      <?php echo $__env->make('layouts.front.category-sub', ['subs' => $category->children], \Illuminate\Support\Arr::except(get_defined_vars(), array('__data', '__path')))->render(); ?>
                <?php else: ?>
                    <a <?php if(request()->segment(2) === $category->slug): ?> class="active"
                       <?php endif; ?> href="<?php echo e(route('front.category.slug', $category->slug)); ?>"><?php echo e($category->name); ?> </a>
                <?php endif; ?>
 
            </li>
            <?php if($loop->last): ?>
        </ul>
    <?php endif; ?>
<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
Arguments
"Undefined variable: rootCategories (View: C:\laragon\www\laracom\resources\views\layouts\front\category-nav.blade.php) (View: C:\laragon\www\laracom\resources\views\layouts\front\category-nav.blade.php) ◀"

Kindly assist me. Thanks in Advance

automica's avatar

@hackroot looks like you've missed a bit of copy and paste:

https://github.com/jsdecena/laracom/compare/master...iammikek:feature/subcategories

project/app/Providers/GlobalTemplateServiceProvider.php 


public function boot()


        view()->composer(['layouts.front.app', 'front.categories.sidebar-category'], function ($view) {

            $view->with('categories', $this->getCategories());

            $view->with('rootCategories', $this->getRootCategories());

            $view->with('cartCount', $this->getCartCount());

        });
hackroot's avatar

I cross checked and recopied and pasted the code but the error persists, below is my globaltemplateserviceprovider code;

app/Providers/GlobalTemplateServiceProvider.php

<?php

namespace App\Providers;

use App\Shop\Carts\Repositories\CartRepository;
use App\Shop\Carts\ShoppingCart;
use App\Shop\Categories\Category;
use App\Shop\Categories\Repositories\CategoryRepository;
use App\Shop\Employees\Employee;
use App\Shop\Employees\Repositories\EmployeeRepository;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\ServiceProvider;

/**
 * Class GlobalTemplateServiceProvider
 * @package App\Providers
 * @codeCoverageIgnore
 */
class GlobalTemplateServiceProvider extends ServiceProvider
{
    /**
     * Register bindings in the container.
     *
     * @return void
     */
    public function boot()
    {
        view()->composer([
            'layouts.admin.app',
            'layouts.admin.sidebar',
            'admin.shared.products'
        ], function ($view) {
            $view->with('admin', Auth::guard('employee')->user());
        });

        view()->composer(['layouts.front.app', 'front.categories.sidebar-category'], function ($view) {

            $view->with('categories', $this->getCategories());

            $view->with('rootCategories', $this->getRootCategories());

            $view->with('cartCount', $this->getCartCount());

        });

        /*
         * breadcrumbs
         */
        view()->composer([
            "layouts.admin.app"
        ], function ($view) {
            $breadcrumb = [
                ["name" => "Dashboard", "url" => route("admin.dashboard"), "icon" => "fa fa-dashboard"],
            ];

            $paths = request()->segments();
            if (count($paths) > 1) {
                foreach ($paths as $key => $pah) {
                    if ($key == 1)
                        $breadcumb[] = ["name" => ucfirst($pah), "url" => request()->getBaseUrl() . "/" . $paths[0] . "/" . $paths[$key], 'icon' => config("module.admin." . $pah . ".icon")];
                    elseif ($key == 2)
                        $breadcumb[] = ["name" => ucfirst($pah), "url" => request()->getBaseUrl() . "/" . $paths[0] . "/" . $paths[1] . "/" . $paths[$key], 'icon' => config("module.admin." . $pah . ".icon")];
                }
            }
            $view->with(
                [
                    "breadcumbs" => $breadcumb
                ]
            );
        });


        view()->composer(['layouts.front.category-nav'], function ($view) {
            $view->with('categories', $this->getCategories());
        });
    }

    /**
     * Get all the categories
     *
     */
    private function getCategories()
    {
        $categoryRepo = new CategoryRepository(new Category);
        return $categoryRepo->listCategories('name', 'asc', 1)->whereIn('parent_id', [1]);
    }

   /**
     * Get all the root categories
     * @return Collection
     */
    private function getRootCategories()
    {
        $categoryRepo = new CategoryRepository(new Category);

        return $categoryRepo->rootCategories();
    }

    /** 
     * @return int
     */
    private function getCartCount()
    {
        $cartRepo = new CartRepository(new ShoppingCart);
        return $cartRepo->countItems();
    }

    /**
     * @param Employee $employee
     * @return bool
     */
    private function isAdmin(Employee $employee)
    {
        $employeeRepo = new EmployeeRepository($employee);
        return $employeeRepo->hasRole('admin');
    }
}

hackroot's avatar

I get the error when I try visit the main url as in "laracom.test" so I presume that should be the index.blade.php page

automica's avatar

@hackroot feels like a cache issue.

can you run the following command in terminal and report back

 php artisan optimize:clear
hackroot's avatar

ok

However I have found why I had the error, earliar while trying to solve the issue myself i called the @include('layouts.front.category-nav') in place of @include('layouts.front.home-slider') and that was giving me the error earlier. Am really sorry I disturbed you. But it's working fine now. I would be glad if you can assist me in hosting the project.

hackroot's avatar

yeah earlier i was running the laracom there i put an opencart there recently. However to host the laravel i used a a structure like these

../myapp
	/app
	/
../public_html
	/css
	/js
	/img
	/vendor
	index.php

however am told its not advisable and also the system could not access my uploaded images.

automica's avatar

@hackroot I would suggest you start a new ticket for your hosting question as will make your question more visible.

the thing to note with the hosting for this, is that its running on laravel 5.7 currently.

hackroot's avatar

okay, Thanks a lot. I will note that.

1 like
automica's avatar

@hackroot if you are happy with this code working now can you mark this topic as resolved?

Be sure to tag me when you have got your site hosted as I would like to see what you have built.

Good luck

Next

Please or to participate in this conversation.