artkonekt / menu

Laravel Menu Component
MIT License
26 stars 150 forks source link

Issue in creating new sidebar menu from sidebar #8

Closed mtkumar82 closed 1 year ago

mtkumar82 commented 1 year ago

Hi, I installed your extension in my laravel9, I created service provide and registered it in app.php file, When I am trying to access the sidebar in my blade file its showing be error like

image

Below is the code of my service provider.

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use View;
//use Konekt\Menu;
class SidebarnavServiceProvider extends ServiceProvider
{
    /**
     * Register services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot()
    {

       View::composer('*', function($view)

       {

            $navbars=  \Menu::create('sidebar_left'); // will be $mainMenu in views
            $navbars->addItem('Home',  '/');
            $navbars->addItem('About', 'about');
            $view->with('navbars', $navbars);

       });

    }
}

AND in my blade file I use the below code.

{{-- Render with the built in 'ul' renderer --}}
                {!! $navbars->render('ul') !!}

                {{--Or render items manually--}}
                <nav>
                    @foreach($navbars->items as $item)
                        <div class="nav-link><a href="{{ $item->url }}">{{ $item->title }}</a></div>
                    @endforeach
                </nav>

Can you please check and tell me where I am making the mistake?

Thanks, Jarnail

fulopattila122 commented 1 year ago

The easiest way is to pass the share option in the Menu::create() call:

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Konekt\Menu\Facades\Menu;

class SidebarnavServiceProvider extends ServiceProvider
{
    public function boot()
    {
        $navbars = Menu::create('sidebar_left', ['share' => 'navbars']); // will be available as $navbars in all views
        $navbars->addItem('Home',  '/');
        $navbars->addItem('About', 'about');
    }
}

See also: https://github.com/artkonekt/menu#access-menu-in-views

fulopattila122 commented 1 year ago

:bulb: Just a tip, but likely you don't need a separate service provider for this; it's OK to simply add these 3 lines to the AppServiceProviders::boot() method

mtkumar82 commented 1 year ago

Hi,

Thanks , You solution works for me, I need to show sidebar and top menu's per module based, I created Modules in laravel and each modules have their specific menu's, How I can add those in Main menu bar, So that If I add menu's in one module, they should be added in existing main menu, already created in other modules. Like

We have Module

Items : This Modules have menu's like , Add Items manage Items , View Items etc Reports:- In this module, We are fetching all reports from Amazon and showing them one by one in separate menus associated with report modules,

Same like this we have more than 20 modules and I wish to have menu seprated for each module , But must be show in main menu along with other menu's, If we have to disable any module , menu's related to that module should be disabled. Please suggest the solution how we can do that?

Jarnail

fulopattila122 commented 1 year ago

If you have a modular structure, then separate service providers can be a good approach.

In each of them you can extend the menu by something like:

class Module1ServiceProvider extends ServiceProvider
{
    public function boot()
    {
        $menu = Menu::get('sidebar_left');
        $module1Submenu = $menu->addItem('module1', __('Module 1'));
        $module1Submenu
            ->addSubItem('products', __('Products'), ['route' => 'module1.admin.product.index'])
    }
}
mtkumar82 commented 1 year ago

Hi,

Thanks for your help, I have one more question about it, I created a module with name AmazonRepricerItems and have multiple controllers inside it, I created a service provider there inside the module and create modules menu. like below

namespace Modules\AmazonRepricer\Providers;

//use Illuminate\Support\ServiceProvider;
use Konekt\Menu\Facades\Menu;
use App\Providers\MainnavigationServiceProvider as ServiceProvider;

class MainmenuServiceProvider extends ServiceProvider
{
    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Get the services provided by the provider.
     *
     * @return array
     */
    public function provides()
    {
        return [];
    }
    public function boot()
    {
        $navbars = Menu::get('mainmenu');       
        $navbars->addItem('amazon_repricer', 'Repricer Tools',['action' => 'AmazonRepricerItems@index']);
        $navbars->getItem('amazon_repricer')->addSubItem('items', 'Items',['action' => 'AmazonRepricerItems@index']);
        $navbars->getItem('amazon_repricer')->addSubItem('noactiveoffers', 'No Activeoffers',['action' => 'AmazonRepricerItems@noactiveoffers']);
        $navbars->getItem('amazon_repricer')->addSubItem('nooffersitems', 'No Offersitems',['action' => 'AmazonRepricerItems@nooffersitems']);       

        $navbars->getItem('amazon_repricer')->addSubItem('latestproduct', 'Latestproduct',['action' => 'AmazonRepricerItems@latestproduct']);
        $navbars->getItem('amazon_repricer')->addSubItem('bookamrks', 'Manage Bookmarks',['action' => 'AmazonRepricerBookmarks@index']);
        $navbars->getItem('amazon_repricer')->addSubItem('offer_category', 'Manage Categories',['action' => 'AmazonOfferCategory@index']);       

        $navbars->getItem('amazon_repricer')->addSubItem('dashboard', 'Dashboard',['action' => 'AmazonRepricerDashboard@index']);
        $navbars->getItem('amazon_repricer')->addSubItem('managesalelimit', 'Manage Sales Limit',['action' => 'AmazonRepricerDashboard@setsaleslimit']);
        $navbars->getItem('amazon_repricer')->addSubItem('addressbook', 'Manage Address Book',['action' => 'AmazonAddressbook@index']);       

        $navbars->getItem('amazon_repricer')->addSubItem('resetsubscription', 'Reset Notification Subscription',['action' => 'AmazonSubscriptionReset@index']);
        $navbars->getItem('amazon_repricer')->addSubItem('amazon_package', 'Amazon Package Templates',['action' => 'AmazonPackage@index']);
        $navbars->getItem('amazon_repricer')->addSubItem('amazon_cronjob', 'Cronjobs Progress',['action' => 'AmazonCronjob@index']);       

        $navbars->getItem('amazon_repricer')->addSubItem('removeplancart', 'Removal Cart History',['action' => 'AmazonRepricerRemoveplancart@view_remove_carts']);
        $navbars->getItem('amazon_repricer')->addSubItem('create_asin', 'Create New ASIN',['action' => 'AmazonCreateAsin@create_product']);
        $navbars->getItem('amazon_repricer')->addSubItem('manage_create_asin', 'Manage New Created ASIN',['action' => 'AmazonCreateAsin@index']);       

        $navbars->addItem('repricer_reports', 'Reports',['action' => 'AmazonRepricerShipmentplan@index']);

        $navbars->getItem('repricer_reports')->addSubItem('shipmentplan', 'Shipment Plan',['action' => 'AmazonRepricerShipmentplan@index']);
        $navbars->getItem('repricer_reports')->addSubItem('viewfeedback', 'Seller Feedbacks',['action' => 'AmazonRepricerDashboard@feedback']);
        $navbars->getItem('repricer_reports')->addSubItem('sales_reports', 'Sales',['action' => 'AmazonRepricerDashboard@viewsale']);
        // Sales Report Sub Menu 
        $navbars->getItem('sales_reports')->addSubItem('viewsale', 'View Sales',['action' => 'AmazonRepricerDashboard@viewsale']);

        // financial_reports

        $navbars->getItem('repricer_reports')->addSubItem('financial_reports', 'Financial',['action' => 'AmazonFinancialGroup@index']);
        $navbars->getItem('financial_reports')->addSubItem('financial_group', 'Financial Group Data',['action' => 'AmazonFinancialGroup@index']);
        //removal_reports
        $navbars->getItem('repricer_reports')->addSubItem('removal_reports', 'Removals',['action' => 'AmazonRemovalReport@index']);
        $navbars->getItem('removal_reports')->addSubItem('removal_report', 'Removal Plan Report',['action' => 'AmazonRemovalReport@index']);
        $navbars->getItem('removal_reports')->addSubItem('recomanded_removal', 'Recomanded Removal',['action' => 'AmazonRecomandedRemoval@index']);
        $navbars->getItem('removal_reports')->addSubItem('removalshipment', 'Removal Shipment Detail Data',['action' => 'AmazonRemovalShipmentReport@index']);
        //inventory_reports
        $navbars->getItem('repricer_reports')->addSubItem('inventory_reports', 'Inventory',['action' => 'AmazonInventoryData@index']);
        $navbars->getItem('inventory_reports')->addSubItem('inventory_data', 'Country Inventory Data',['action' => 'AmazonInventoryData@index']);
        $navbars->getItem('inventory_reports')->addSubItem('inventory_summary', 'Inventory Summary',['action' => 'AmazonInventorySummary@index']);
        $navbars->getItem('inventory_reports')->addSubItem('inventory_monthly_data', 'Monthly Inventory Data',['action' => 'AmazonInventoryMonthlyData@index']);
        $navbars->getItem('inventory_reports')->addSubItem('inventory_adjustment', 'Inventory Adjustment',['action' => 'AmazonInventoryAdjustment@index']);
        $navbars->getItem('inventory_reports')->addSubItem('ledger_summery', 'Ledger Summary',['action' => 'AmazonLedgerSummery@index']);
        $navbars->getItem('inventory_reports')->addSubItem('defective_product', 'Defective Product',['action' => 'AmazonDefectiveProduct@index']);
        $navbars->getItem('inventory_reports')->addSubItem('reimbursement', 'Reimbursement Report',['action' => 'AmazonReimbursement@index']);
        $navbars->getItem('inventory_reports')->addSubItem('inventory_current_data', 'FBA Daily Inventory History',['action' => 'AmazonInventoryCurrentData@index']);
        $navbars->getItem('inventory_reports')->addSubItem('customer_return', 'Customer Returns Data',['action' => 'CustomerReturn@index']);
        $navbars->getItem('inventory_reports')->addSubItem('inventory_receipt', 'Inventory Arrival Data',['action' => 'AmazonInventoryReceipt@index']);
        // order_reports
        $navbars->getItem('repricer_reports')->addSubItem('order_reports', 'Orders',['action' => 'LastUpdatedOrder@index']);
        $navbars->getItem('order_reports')->addSubItem('last_updated_order', 'Last Updated Orders',['action' => 'LastUpdatedOrder@index']);
        $navbars->getItem('order_reports')->addSubItem('order_report', 'Order saletax report',['action' => 'OrderReport@index']);

        // fba_inventory_reports
        $navbars->getItem('repricer_reports')->addSubItem('fba_inventory_reports', 'FBA Fulfilment',['action' => 'AmazonRepricerDashboard@inventorydata']);
        $navbars->getItem('fba_inventory_reports')->addSubItem('inventorydata', 'FBA Fulfilment Shipments',['action' => 'AmazonRepricerDashboard@inventorydata']);
        $navbars->getItem('fba_inventory_reports')->addSubItem('removalorders', 'FBA Fulfilment Removals Orders',['action' => 'AmazonRepricerDashboard@viewremovalorder']);
        // custom_inventory_reports
        $navbars->getItem('repricer_reports')->addSubItem('custom_inventory_reports', 'FBA Fulfilment',['action' => 'CustomInventoryReport@index']);       
    }
}

I extension the main service provider to have menu merge there, But when I am checking it in browser its giving me below error

image

While have controller exist in modules/AmazonRepricer/Http/Controllers/AmazonRepricerItemsController.php But its not able to read it , Can you please help me how it will show all menus there associated with other.

Thanks

fulopattila122 commented 1 year ago

Add a public method named index to the AmazonRepricerItemsController class

mtkumar82 commented 1 year ago

Hi,

Thanks for your response, I already have it in Modules\AmazonRepricer\http\Controllers\AmazonRepricerItemsController. Please check below code.

<?php

namespace Modules\AmazonRepricer\Http\Controllers;

use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;

class AmazonRepricerItemsController extends Controller
{
    /**
     * Display a listing of the resource.
     * @return Renderable
     */
    public function index()
    {
        return view('amazonrepricer::index');
    }

    /**
     * Show the form for creating a new resource.
     * @return Renderable
     */
    public function create()
    {
        return view('amazonrepricer::create');
    }

    /**
     * Store a newly created resource in storage.
     * @param Request $request
     * @return Renderable
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Show the specified resource.
     * @param int $id
     * @return Renderable
     */
    public function show($id)
    {
        return view('amazonrepricer::show');
    }

    /**
     * Show the form for editing the specified resource.
     * @param int $id
     * @return Renderable
     */
    public function edit($id)
    {
        return view('amazonrepricer::edit');
    }

    /**
     * Update the specified resource in storage.
     * @param Request $request
     * @param int $id
     * @return Renderable
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     * @param int $id
     * @return Renderable
     */
    public function destroy($id)
    {
        //
    }
    // No Active Offers
    public function noactiveoffers(){
             die("HERE");
    }
    public function latestproduct(){
        die("latestproduct");
    }
}
fulopattila122 commented 1 year ago

Well, it's no longer an issue related to this library, and I'm sorry but I can't provide generic Laravel support over here.

As a last tip: the namespace of your controller and where Laravel is trying to find it are not matching.