Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Adminmetronic Bundle Laravel Package

cwd/adminmetronic-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install the Bundle

    composer require cwd/adminmetronic-bundle
    

    Ensure your composer.json includes the package under require.

  2. Copy Metronic Assets

    • Purchase Metronic Admin Template.
    • Extract the template and copy the assets/, sass/, and templates/ folders into your Laravel project’s public/ directory.
    • Verify the structure:
      public/
      ├── assets/          # Metronic JS/CSS assets
      ├── sass/            # SCSS source files
      └── templates/       # Admin4 template files
      
  3. Enable the Bundle Add to config/app.php under providers:

    Cwd\AdminMetronicBundle\CwdAdminMetronicBundle::class,
    

    Publish the bundle’s assets (if needed):

    php artisan vendor:publish --provider="Cwd\AdminMetronicBundle\CwdAdminMetronicBundle" --tag=assets
    
  4. First Use Case: Basic Admin Layout Extend the bundle’s base template in resources/views/layouts/app.blade.php:

    @extends('AdminMetronicBundle::base')
    @section('content')
        <!-- Your admin content here -->
    @endsection
    

Implementation Patterns

1. Template Inheritance

  • Extend Metronic’s Base Template: Use @extends('AdminMetronicBundle::base') in your views to inherit Metronic’s layout (header, sidebar, footer). Override sections like content, sidebar, or scripts:

    @section('sidebar')
        @include('partials.admin-sidebar')
    @endsection
    
  • Dynamic Sidebars: Use Metronic’s built-in sidebar components (e.g., AdminMetronicBundle::sidebar) and customize via Twig/Laravel Blade:

    @include('AdminMetronicBundle::sidebar', ['items' => $menuItems])
    

2. Asset Management

  • SCSS Compilation: The bundle assumes you’re using Metronic’s SCSS files. Integrate with Laravel Mix or Vite:

    // webpack.mix.js
    mix.sass('resources/sass/admin.scss', 'public/css');
    

    Link the compiled CSS in your layout:

    <link href="{{ asset('css/admin.css') }}" rel="stylesheet">
    
  • JavaScript Dependencies: Load Metronic’s JS via the scripts section:

    @section('scripts')
        @parent  // Loads Metronic's base scripts
        <script src="{{ asset('assets/global/scripts/datatable.js') }}"></script>
    @endsection
    

3. Routing and Admin Pages

  • Admin Routes: Prefix admin routes in routes/web.php:

    Route::prefix('admin')->middleware(['auth', 'admin'])->group(function () {
        Route::get('/dashboard', 'AdminController@dashboard')->name('admin.dashboard');
    });
    

    Use Metronic’s template files for views (e.g., templates/admin/dashboard.html.twig → convert to Blade).

  • Dynamic Views: Map Metronic’s template files to Laravel routes:

    Route::get('/users', function () {
        return view('AdminMetronicBundle::admin/users', ['users' => User::all()]);
    });
    

4. Integration with Laravel Features

  • Authentication: Use Laravel’s auth scaffolding and override Metronic’s login template:

    @auth
        @extends('AdminMetronicBundle::base')
        @section('content')
            @include('auth.login')
        @endsection
    @endauth
    
  • Form Handling: Leverage Metronic’s form components (e.g., AdminMetronicBundle::form) in Blade:

    {!! Form::open(['route' => 'admin.users.store']) !!}
        @include('AdminMetronicBundle::form/fields', ['fields' => $formFields])
        {!! Form::submit('Save') !!}
    {!! Form::close() !!}
    

Gotchas and Tips

Pitfalls

  1. Outdated Template Support:

    • The bundle only supports Admin4 (released in 2015). Metronic has evolved significantly since (e.g., Admin5+).
    • Workaround: Manually adapt newer Metronic templates or fork the bundle.
  2. Asset Path Assumptions:

    • The bundle expects assets in public/assets/, public/sass/, etc. Misplaced files break rendering.
    • Fix: Verify paths in config/admin_metronic.php (if published) or override in your layout.
  3. Twig vs. Blade:

    • The bundle uses Twig syntax (e.g., {{ variable }}). Mixing with Blade may cause issues.
    • Tip: Use @php echo $variable @endphp for Twig variables in Blade or rewrite templates.
  4. No Active Development:

    • Last release: 2015. Compatibility with modern Laravel (9.x+) is untested.
    • Mitigation: Patch the bundle or use a community fork (e.g., laravel-metronic).

Debugging Tips

  • Broken CSS/JS: Check browser console for 404s on public/assets/.... Ensure files are copied correctly.

    ls public/assets/ -R  # Verify structure
    
  • Template Overrides Not Working: Clear cached views:

    php artisan view:clear
    php artisan cache:clear
    
  • Sidebar/Layout Issues: Metronic’s JS relies on specific HTML structure. Inspect the rendered source to match the template’s expectations.

Extension Points

  1. Custom Templates:

    • Add new templates to public/templates/ and extend the bundle’s TemplateEngine service.
    • Example: Create public/templates/admin/custom.html.twig and override the base template path.
  2. Dynamic Configuration: Publish the config:

    php artisan vendor:publish --provider="Cwd\AdminMetronicBundle\CwdAdminMetronicBundle" --tag=config
    

    Customize config/admin_metronic.php for:

    • Default template paths.
    • Asset versions (for cache busting).
  3. Laravel Mix/Vite Integration: Override the default asset pipeline by extending the bundle’s AssetManager:

    // app/Providers/AppServiceProvider.php
    public function register()
    {
        $this->app->extend('admin_metronic.asset_manager', function ($manager) {
            $manager->setJsPath('path/to/custom/js');
            return $manager;
        });
    }
    

Pro Tips

  • Use Metronic’s Components: Leverage pre-built components (e.g., datatables, charts) via their JS/CSS:

    <!-- Example: DataTable -->
    <div class="table-responsive">
        <table class="table table-striped table-bordered table-hover" id="sample_1">
            <!-- Data here -->
        </table>
    </div>
    <script src="{{ asset('assets/global/scripts/datatable.js') }}"></script>
    <script>
        jQuery(document).ready(function() {
            $('#sample_1').dataTable();
        });
    </script>
    
  • Dark/Light Mode: Metronic supports themes. Toggle via CSS classes:

    <body class="skin-default">  <!-- Default theme -->
    <body class="skin-dark">    <!-- Dark theme -->
    
  • Localization: Metronic includes RTL support. Add dir="rtl" to <html> and load RTL assets:

    <html dir="rtl">
    <link href="{{ asset('assets/global/plugins/rtl/rtl.css') }}" rel="stylesheet">
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware