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

Laravel Sabhero Estimator Laravel Package

fuelviews/laravel-sabhero-estimator

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require fuelviews/laravel-sabhero-estimator
    php artisan sabhero-estimator:install
    
    • This publishes migrations, config, and assets to resources/views/vendor/sabhero-estimator and config/sabhero-estimator.php.
  2. First Use Case:

    • Run migrations:
      php artisan migrate
      
    • Access the estimator via a Livewire component or Filament resource (if configured). The default route (/estimator) is registered in the package.
  3. Quick Start:

    • Use the provided EstimatorForm Livewire component in your Blade view:
      @livewire('sabhero-estimator::estimator-form')
      
    • For Filament integration, register the resource in app/Providers/Filament/AdminPanelProvider.php:
      public function panel(Panel $panel): Panel
      {
          return $panel
              ->resources([
                  \SabheroEstimator\Filament\Resources\EstimateResource::class,
              ]);
      }
      

Implementation Patterns

Core Workflows

  1. Project Creation:

    • Use the Estimate model to create new estimates:
      use SabheroEstimator\Models\Estimate;
      
      $estimate = Estimate::create([
          'project_name' => 'Living Room Refresh',
          'project_type' => 'interior',
          'client_name' => 'John Doe',
          'client_email' => 'john@example.com',
      ]);
      
    • Attach rooms or areas via the estimateRooms() relationship:
      $estimate->estimateRooms()->attach($roomId, ['area_sqft' => 1200, 'walls' => 4]);
      
  2. Livewire Integration:

    • Extend the EstimatorForm component to customize logic:
      namespace App\Livewire;
      
      use SabheroEstimator\Livewire\EstimatorForm as BaseEstimatorForm;
      
      class CustomEstimatorForm extends BaseEstimatorForm
      {
          public function calculateEstimate()
          {
              // Override or extend calculation logic
              $this->estimate->material_cost = $this->customCalculation();
          }
      }
      
    • Use the estimateUpdated event to trigger actions post-calculation:
      protected function estimateUpdated()
      {
          $this->emit('estimateCalculated', $this->estimate);
      }
      
  3. Filament Resource Customization:

    • Override the Filament resource tables/columns:
      public static function table(Table $table): Table
      {
          return $table
              ->columns([
                  Columns\TextColumn::make('project_name')
                      ->searchable(),
                  Columns\TextColumn::make('status')
                      ->badge(),
                  Columns\TextColumn::make('total_cost')
                      ->money('USD'),
              ]);
      }
      
  4. API Endpoints:

    • Use the EstimateController to expose endpoints:
      Route::apiResource('estimates', \SabheroEstimator\Http\Controllers\EstimateController::class);
      
    • Fetch estimates with relationships:
      return Estimate::with(['estimateRooms', 'materials'])->get();
      

Integration Tips

  • Validation: Extend the EstimateRequest form request to add custom rules:
    namespace App\Http\Requests;
    
    use SabheroEstimator\Http\Requests\EstimateRequest as BaseEstimateRequest;
    
    class CustomEstimateRequest extends BaseEstimateRequest
    {
        public function rules()
        {
            return array_merge(parent::rules(), [
                'custom_field' => 'required|string',
            ]);
        }
    }
    
  • Localization: Override language files in resources/lang/vendor/sabhero-estimator.
  • Asset Customization: Publish and modify the package’s assets:
    php artisan vendor:publish --tag=sabhero-estimator-assets
    

Gotchas and Tips

Pitfalls

  1. Migration Conflicts:

    • If you’ve manually created estimates or estimate_rooms tables, drop them before running sabhero-estimator:install to avoid conflicts.
    • Fix: Backup your database and run php artisan migrate:fresh if needed.
  2. Livewire Component Naming:

    • Avoid naming custom Livewire components the same as the package’s (EstimatorForm), as it may override the package’s functionality.
    • Tip: Prefix your components (e.g., CustomEstimatorForm).
  3. Filament Resource Registration:

    • Ensure the Filament panel is properly configured in app/Providers/Filament/AdminPanelProvider.php. Missing this will break the /admin/estimates route.
    • Debug: Check php artisan filament:install if Filament resources aren’t loading.
  4. Calculation Logic:

    • The package uses a default calculation algorithm. Override the calculateEstimate() method in your Livewire component if you need custom logic.
    • Warning: Hardcoding values in the base component may break updates. Extend instead.
  5. Asset Loading:

    • If CSS/JS assets aren’t loading, verify the publish tag:
      php artisan vendor:publish --tag=sabhero-estimator-assets --force
      
    • Tip: Check the browser’s network tab for 404 errors on /vendor/sabhero-estimator/....

Debugging

  1. Log Estimates:

    • Enable logging in config/sabhero-estimator.php:
      'logging' => [
          'enabled' => true,
          'channel' => 'single',
      ],
      
    • Check logs at storage/logs/laravel.log.
  2. Livewire Events:

    • Use wire:ignore or wire:model.debounce to optimize form performance:
      <input wire:model.debounce.500ms="area_sqft">
      
  3. Database Seeding:

    • Seed sample data with:
      php artisan db:seed --class=SabheroEstimatorDatabaseSeeder
      

Extension Points

  1. Custom Fields:

    • Add fields to the estimate_rooms table via a migration:
      Schema::table('estimate_rooms', function (Blueprint $table) {
          $table->string('custom_field')->nullable();
      });
      
    • Update the Livewire component to handle the new field.
  2. Material Pricing:

    • Extend the Material model to add custom pricing logic:
      namespace App\Models;
      
      use SabheroEstimator\Models\Material;
      
      class CustomMaterial extends Material
      {
          public function getPricePerUnit()
          {
              return $this->price_per_unit * 1.1; // Add 10% markup
          }
      }
      
  3. Webhooks:

    • Listen for estimate.created or estimate.updated events to trigger external actions (e.g., email notifications):
      use SabheroEstimator\Events\EstimateCreated;
      
      Event::listen(EstimateCreated::class, function ($estimate) {
          // Send email or update CRM
      });
      
  4. PDF Generation:

    • Use the EstimatePdf class to generate custom PDFs:
      use SabheroEstimator\Services\EstimatePdf;
      
      $pdf = new EstimatePdf($estimate);
      return $pdf->download('estimate.pdf');
      
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.
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
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver