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

Bauhaus Laravel Package

krafthaus/bauhaus

Bauhaus is a Laravel 4 admin generator for building clean admin interfaces with model-driven lists, forms, filters, scoping, and exporting. Includes asset/config publishing, multilingual UI, and integrates with Intervention Image for media handling.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require krafthaus/bauhaus
    php artisan asset:publish krafthaus/bauhaus
    php artisan config:publish krafthaus/bauhaus
    
    • Publish assets (CSS/JS) and config files to your project.
  2. Service Provider: Ensure Krafthaus\Bauhaus\BauhausServiceProvider is registered in config/app.php under providers.

  3. First Use Case:

    • Define a model (e.g., User) and generate a CRUD interface:
      // routes.php
      Route::resource('admin/users', 'Admin\UserController');
      
    • Create a controller extending Krafthaus\Bauhaus\Controllers\BauhausController:
      namespace App\Http\Controllers\Admin;
      use Krafthaus\Bauhaus\Controllers\BauhausController;
      
      class UserController extends BauhausController {
          protected $model = 'App\User';
      }
      
    • Visit /admin/users to see the auto-generated admin panel.

Key First Steps

  • Model Binding: Bauhaus auto-discovers models via controller properties ($model).
  • Configuration: Customize via config/bauhaus.php (e.g., default columns, filters, or form fields).
  • Asset Compilation: Run php artisan build (if using Laravel Mix) to compile Bauhaus assets.

Implementation Patterns

Core Workflows

  1. CRUD Generation:

    • Extend BauhausController and set $model to auto-generate list/views/edit forms.
    • Customize via $columns, $filters, or $formFields in the controller:
      protected $columns = ['id', 'name', 'email'];
      protected $filters = ['name', 'email'];
      protected $formFields = ['name', 'email', 'password'];
      
  2. Scoping and Filtering:

    • Use $scopes to define model query scopes:
      protected $scopes = ['active', 'inactive'];
      
    • Dynamically filter lists via URL parameters (e.g., /admin/users?name=John).
  3. Exporting Data:

    • Enable CSV/Excel exports by adding export to $columns:
      protected $columns = ['id', 'name', 'email', 'export'];
      
  4. Custom Views:

    • Override default views by publishing Bauhaus templates:
      php artisan vendor:publish --tag=bauhaus-views
      
    • Modify resources/views/vendor/bauhaus/ to customize layouts, forms, or lists.

Integration Tips

  • Authentication: Pair with Laravel's built-in auth or packages like spatie/laravel-permission for role-based access.
  • Validation: Use Laravel's validation rules in $formFields:
    protected $formFields = [
        'name' => ['rules' => 'required|max:255'],
        'email' => ['rules' => 'required|email']
    ];
    
  • Relationships: Display related models via $columns:
    protected $columns = ['id', 'name', 'posts.count'];
    
  • Localization: Switch languages via config/bauhaus.php:
    'locale' => 'nl', // Dutch
    

Gotchas and Tips

Common Pitfalls

  1. Asset Publishing:

    • Forgetting to run php artisan asset:publish krafthaus/bauhaus may break CSS/JS.
    • Fix: Always publish assets after installation or updates.
  2. Model Not Found:

    • Ensure the $model property in your controller matches a fully qualified namespace (e.g., App\User).
    • Debug: Verify the model exists and is autoloaded (composer dump-autoload).
  3. Configuration Overrides:

    • Global config in config/bauhaus.php may conflict with controller-specific settings.
    • Tip: Use mergeConfigFrom in your controller to override defaults:
      public function __construct() {
          $this->mergeConfigFrom(__DIR__.'/bauhaus.php', 'bauhaus');
      }
      
  4. Database Scoping Issues:

    • Scopes defined in $scopes must exist as model methods (e.g., scopeActive).
    • Fix: Add scopes to your model:
      public function scopeActive($query) {
          return $query->where('active', 1);
      }
      

Debugging Tips

  • Log Queries: Enable Laravel's query logging in config/database.php to debug scope/filter issues.
  • View Debugging: Use Laravel's dd() or dump() in custom views to inspect data.
  • Asset Paths: Verify published assets are linked correctly in resources/views/vendor/bauhaus/layouts/app.blade.php.

Extension Points

  1. Custom Columns:

    • Extend functionality by creating custom column types (e.g., for nested relationships or computed fields).
    • Example: Add a StatusColumn class in app/Bauhaus/Columns.
  2. Filters:

    • Build reusable filters by extending Krafthaus\Bauhaus\Filters\Filter:
      namespace App\Bauhaus\Filters;
      use Krafthaus\Bauhaus\Filters\Filter;
      
      class CustomFilter extends Filter {
          public function apply($query) {
              return $query->where('custom_field', $this->value);
          }
      }
      
  3. Events:

    • Listen to Bauhaus events (e.g., bauhaus.saving, bauhaus.deleting) in EventServiceProvider:
      protected $listen = [
          'bauhaus.saving' => ['App\Listeners\LogAdminAction'],
      ];
      
  4. Middleware:

    • Restrict access to admin routes via middleware:
      Route::group(['middleware' => 'admin'], function () {
          Route::resource('admin/users', 'Admin\UserController');
      });
      

Pro Tips

  • Partial Updates: Use PUT requests with Bauhaus to update specific fields without reloading the entire form.
  • Bulk Actions: Enable bulk delete/update by adding bulk to $columns and implementing bulkAction in your controller.
  • Testing: Use Laravel's HTTP tests to verify Bauhaus routes:
    $this->get('/admin/users')->assertStatus(200);
    
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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui