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

Page Bundle Laravel Package

axstrad/page-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup for Laravel Integration (Symfony 2 → Laravel Adaptation)

Since this is a Symfony 2 bundle, direct Laravel integration isn’t natively supported. However, you can adapt its core logic (page management, SEO, and content handling) into Laravel using these steps:

  1. Extract Core Functionality

    • Clone the repo and inspect:
      • AxstradPageBundle/Resources/config/doctrine/ (Doctrine ORM entities like Page).
      • AxstradPageBundle/Controller/ (e.g., PageController for routing).
      • AxstradPageBundle/DependencyInjection/ (services/configuration).
    • Focus on:
      • The Page entity (likely extends axstrad/content for content management).
      • SEO metadata handling (via axstrad/seo-bundle).
      • Routing logic (e.g., dynamic page slugs).
  2. Laravel Equivalent Setup

    • Install Dependencies:
      composer require doctrine/dbal doctrine/orm illuminate/database
      composer require axstrad/content axstrad/seo-bundle  # If available via Packagist or forked
      
    • Create a Laravel Migration: Adapt the Page entity schema (from AxstradPageBundle/Resources/config/doctrine/Page.orm.xml) into a Laravel migration:
      Schema::create('pages', function (Blueprint $table) {
          $table->id();
          $table->string('slug')->unique();
          $table->text('title');
          $table->text('content')->nullable();
          $table->string('template')->default('default');
          $table->timestamps();
      });
      
    • Model Setup:
      namespace App\Models;
      use Illuminate\Database\Eloquent\Model;
      use Axstrad\Content\Traits\Contentable; // Hypothetical trait (adapt from axstrad/content)
      
      class Page extends Model
      {
          use Contentable; // If using axstrad/content
          protected $fillable = ['slug', 'title', 'content', 'template'];
      }
      
  3. First Use Case: Dynamic Page Rendering

    • Route:
      Route::get('/{slug}', [PageController::class, 'show']);
      
    • Controller:
      namespace App\Http\Controllers;
      use App\Models\Page;
      
      class PageController extends Controller
      {
          public function show($slug)
          {
              $page = Page::where('slug', $slug)->firstOrFail();
              return view('pages.' . $page->template, ['page' => $page]);
          }
      }
      
    • View (resources/views/pages/default.blade.php):
      <h1>{{ $page->title }}</h1>
      <div>{!! $page->content !!}</div>
      
  4. SEO Integration

    • Use axstrad/seo-bundle (or Laravel’s spatie/laravel-seo) to attach metadata:
      // In PageController::show()
      $page->seo()->setTitle($page->title);
      $page->seo()->setDescription(substr($page->content, 0, 160));
      

Implementation Patterns

1. Content Management Workflow

  • Admin Panel:
    • Use SonataAdminBundle (Symfony) or Backpack/Laravel for a Laravel admin interface.
    • Adapt the Page CRUD logic from AxstradPageBundle/Controller/PageController.
    • Example Laravel Backpack integration:
      namespace App\Admin;
      use Backpack\CRUD\app\Http\Controllers\OperationCrudController;
      use App\Models\Page;
      
      class PageCrudController extends OperationCrudController
      {
          public function setup()
          {
              CRUD::setModel(\App\Models\Page::class);
              CRUD::setRoute(config('backpack.base.route_prefix') . '/page');
              CRUD::setEntityNameStrings('page', 'pages');
          }
      }
      
  • Content Editing:
    • Leverage axstrad/content for WYSIWYG or markdown support. In Laravel, use laravel-wysiwyg or tymon/jwt-auth for rich content.

2. Routing and Slug Handling

  • Dynamic Routes:
    • Use Laravel’s route model binding:
      Route::get('/{page:slug}', [PageController::class, 'show']);
      
  • Fallback Route:
    Route::fallback(function () {
        return redirect('/404');
    });
    
  • Redirect Old Slugs:
    • Implement a slug_redirects table to handle URL changes:
      Schema::create('slug_redirects', function (Blueprint $table) {
          $table->string('old_slug');
          $table->string('new_slug');
          $table->unique(['old_slug', 'new_slug']);
      });
      

3. Template System

  • View Overrides:
    • Store page-specific templates in resources/views/pages/{template}.blade.php.
    • Default template falls back to default.blade.php.
  • Partial Templates:
    • Use Laravel’s @include or @component for reusable sections (headers, footers).

4. SEO and Metadata

  • Meta Tags:
    • Use spatie/laravel-seo or manually inject tags:
      // In PageController::show()
      $seo = [
          'title' => $page->title,
          'description' => $page->meta_description ?? '',
          'keywords' => $page->keywords ?? '',
      ];
      return view('pages.' . $page->template, ['page' => $page, 'seo' => $seo]);
      
  • Open Graph:
    <!-- In your layout blade file -->
    @if(isset($seo))
        <meta property="og:title" content="{{ $seo['title'] }}">
        <meta property="og:description" content="{{ $seo['description'] }}">
    @endif
    

5. Caching Static Pages

  • Cache Pages:
    $page = Cache::remember("page:{$slug}", now()->addHours(1), function () use ($slug) {
        return Page::where('slug', $slug)->first();
    });
    
  • Cache Tags: Use Laravel’s cache tags to invalidate pages when updated:
    Cache::tags(['pages'])->put("page:{$slug}", $page);
    

Gotchas and Tips

1. Symfony → Laravel Quirks

  • Doctrine ORM:
    • The bundle uses Doctrine ORM. In Laravel, replace with Eloquent or use laravel-doctrine/orm.
    • Example: Install doctrine/dbal and illuminate/database for hybrid setups.
  • Dependency Conflicts:
    • axstrad/seo-bundle and axstrad/content may not be Laravel-compatible. Fork and adapt or use alternatives like:
      • SEO: spatie/laravel-seo
      • Content: laravel-wysiwyg or spatie/laravel-medialibrary.

2. Routing Pitfalls

  • Slug Collisions:
    • Ensure slugs are unique. Add a Laravel observer to auto-generate slugs:
      use Illuminate\Support\Str;
      
      class GenerateSlug
      {
          public function saving($page)
          {
              if (empty($page->slug)) {
                  $page->slug = Str::slug($page->title);
              }
          }
      }
      
    • Register the observer in Page model:
      protected static function boot()
      {
          parent::boot();
          static::saving('GenerateSlug');
      }
      
  • Case Sensitivity:
    • Laravel routes are case-sensitive. Normalize slugs:
      $page->slug = Str::lower($page->slug);
      

3. Performance Tips

  • Eager Load Relationships:
    • If Page has relationships (e.g., author), eager load them:
      $page = Page::with('author')->where('slug', $slug)->first();
      
  • Database Indexes:
    • Add indexes to slug and template columns in migrations:
      $table->string('slug')->unique();
      $table->string('template')->default('default');
      
      Then run:
      php artisan optimize:clear
      

4. Debugging

  • Missing Dependencies:
    • If axstrad/content or axstrad/seo-bundle are missing, check:
      • Fork the bundle and publish it to Packagist.
      • Manually copy the relevant traits/classes into your Laravel project.
  • Route Debugging:
    • Use php artisan route:list to check for conflicts.
    • Test slug routes with:
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