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

Website Bundle Laravel Package

austral/website-bundle

View on GitHub
Deep Wiki
Context7
## Getting Started

### Minimal Setup
1. **Installation**
   Add the bundle via Composer:
   ```bash
   composer require austral/website-bundle

Register the bundle in config/bundles.php:

Austral\WebsiteBundle\AustralWebsiteBundle::class => ['all' => true],
  1. Publish Configuration Publish the default config:

    php artisan austral:website:install
    

    This generates:

    • Database migrations (database/migrations/...)
    • Default routes (config/routes/website.php)
    • Translations (resources/lang/)
  2. First Use Case: Create a Website Define a website in config/website.php:

    'websites' => [
        'main' => [
            'domain' => 'example.com',
            'default_language' => 'en',
            'redirects' => [
                'old-site.com' => '/new-path',
            ],
        ],
    ],
    

    Run migrations:

    php artisan migrate
    
  3. Basic Routing Use the website() helper in routes:

    // routes/website.php
    website()->get('/', 'PageController@home');
    

Implementation Patterns

Core Workflows

1. Multi-Domain Management

  • Dynamic Routing: Use website()->domain() middleware to route requests based on the domain:
    Route::domain('{domain}')->group(function () {
        website()->matchDomain('blog.example.com')->get('/', 'BlogController@index');
    });
    
  • Fallback Domains: Configure fallback domains in config/website.php:
    'fallbacks' => [
        'example.com' => 'www.example.com',
    ],
    

2. Language Handling

  • Auto-Detection: Leverage entity-translate-bundle for language-aware content:
    use Austral\EntityTranslateBundle\Traits\Translatable;
    
    class Page
    {
        use Translatable;
    }
    
  • URL Localization: Generate locale-aware URLs:
    $url = website()->generateUrl('page.show', ['id' => 1], 'fr');
    

3. SEO Integration

  • Meta Tags: Use seo-bundle with the website context:
    $meta = website()->getSeoService()->generateMeta('page.title', 'page.description');
    
  • Sitemap Generation: Auto-generate sitemaps per website:
    php artisan austral:seo:sitemap:generate --website=main
    

4. Content Blocks

  • Reusable Components: Define blocks in the admin panel (via content-block-bundle) and embed them:
    {{ austral_content_block('header') }}
    

5. File Management

  • Media Handling: Store website-specific files:
    $file = website()->getFileService()->upload('logo.png', 'websites/main');
    

Integration Tips

Laravel Ecosystem

  • Service Providers: Extend the bundle’s services in your AppServiceProvider:
    public function register()
    {
        $this->app->extend('website', function ($website) {
            $website->setCustomConfig(['key' => 'value']);
            return $website;
        });
    }
    
  • Events: Listen to website-related events (e.g., WebsiteCreated):
    Event::listen(WebsiteEvents::CREATED, function ($website) {
        Log::info("Website {$website->getName()} created.");
    });
    

Admin Panel (Optional)

  • Custom Admin Routes: Override admin routes in routes/admin.php:
    website()->admin()->get('/websites', 'WebsiteController@index');
    

CLI Tools

  • Generate Commands: Create custom commands extending the bundle’s base:
    namespace App\Console\Commands;
    
    use Austral\WebsiteBundle\Console\WebsiteCommand;
    
    class CustomWebsiteCommand extends WebsiteCommand
    {
        protected $signature = 'austral:website:custom {action}';
        // ...
    }
    

Gotchas and Tips

Pitfalls

  1. Domain Configuration

    • Issue: Redirects may not work if the HTTP_HOST header is missing (e.g., in tests). Fix: Mock the Request object or use website()->setTestDomain('test.example.com').
    • Issue: Multi-domain routing conflicts with Symfony’s default routing. Fix: Ensure website()->domain() middleware is registered before other domain-based routes.
  2. Language Defaults

    • Issue: Default language may not persist if not set in the database. Fix: Explicitly define it in config/website.php and run:
      php artisan austral:website:update-defaults
      
  3. SEO Bundle Dependency

    • Issue: Missing seo-bundle config if not installed. Fix: Install it first:
      composer require austral/seo-bundle
      
  4. File Storage

    • Issue: Files uploaded via entity-file-bundle may not respect website-specific paths. Fix: Use the website-aware service:
      $path = website()->getFileService()->getPath('logo.png', 'websites/main');
      
  5. Caching

    • Issue: Website-specific routes may not clear cache properly. Fix: Use tags in cache:
      $this->addCacheTags(['website:main']);
      

Debugging Tips

  1. Log Website Context Add this to your AppServiceProvider to log the current website:

    public function boot()
    {
        if ($this->app->has('website')) {
            $this->app->booted(function () {
                \Log::debug('Current website:', [
                    'name' => website()->getName(),
                    'domain' => website()->getDomain(),
                ]);
            });
        }
    }
    
  2. Check Middleware Order Ensure website() middleware is registered after locale() but before web:

    $middlewareGroups['web'] = [
        // ...
        \Austral\WebsiteBundle\Http\Middleware\WebsiteMiddleware::class,
        // ...
    ];
    
  3. Validate Config Use the validate command to check your config/website.php:

    php artisan austral:website:validate
    

Extension Points

  1. Custom Website Entities Extend the base Website entity:

    namespace App\Entity;
    
    use Austral\WebsiteBundle\Entity\Website as BaseWebsite;
    
    class Website extends BaseWebsite
    {
        #[ORM\Column]
        private ?string $customField = null;
    
        // Add getters/setters
    }
    

    Update the bundle’s WebsiteType in your AppWebsiteBundle.

  2. Override Templates Copy the bundle’s Twig templates to resources/views/austral/website/ to override them.

  3. Add Custom Fields Use the entity-translate-bundle to add translatable fields to Page or ContentBlock:

    #[ORM\Column]
    #[Assert\NotBlank]
    private ?string $customTitle = null;
    
  4. Hook into Redirects Extend the redirect logic in a service:

    namespace App\Service;
    
    use Austral\WebsiteBundle\Service\WebsiteRedirectService;
    
    class CustomWebsiteRedirectService extends WebsiteRedirectService
    {
        public function getRedirects(): array
        {
            $redirects = parent::getRedirects();
            $redirects['custom.com'] = '/custom-path';
            return $redirects;
        }
    }
    

    Bind it in config/services.yaml:

    services:
        Austral\WebsiteBundle\Service\WebsiteRedirectService: '@App\Service\CustomWebsiteRedirectService'
    
  5. Custom Commands Extend existing commands (e.g., WebsiteCommand) to add functionality:

    namespace App\Console\Commands;
    
    use Austral\WebsiteBundle\Console\WebsiteCommand;
    
    class BackupWebsiteCommand extends WebsiteCommand
    {
        protected $signature = 'austral:website:backup {website}';
        protected $description = 'Backup a website\'s content';
    
        public function handle()
        {
            $website = $this->getWebsite($this->argument('website'));
            // Add backup logic
        }
    }
    

Performance Tips

  1. Cache Website Lookups Cache the website resolver in WebsiteMiddleware:

    $website = Cache::remember("website.{$request->getHost()}", 3600, function () use ($request) {
        return website()->findByDomain($request->getHost());
    });
    
  2. Lazy-Load SEO Data Defer SEO data loading until needed:

    $seoService = website()->get
    
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.
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
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager