Skip to main content

Installation

This guide will walk you through installing and configuring Laravel URL in your Laravel application.

Requirements

  • PHP >= 8.1
  • Laravel >= 10.0
  • Database (MySQL, PostgreSQL, SQLite, or SQL Server)

Installation Steps

Step 1: Install via Composer

Run the following command to install the package:

composer require jobmetric/laravel-url

Step 2: Publish Configuration

Publish the configuration file:

php artisan vendor:publish --tag=url-config

This will create a config/url.php file in your application.

Step 3: Run Migrations

Run the migrations to create the required database tables:

php artisan migrate

This will create two tables:

  • slugs - Stores slug information for models
  • urls - Stores versioned full URL history

Configuration

After publishing the configuration, you can customize the package behavior in config/url.php:

return [
'tables' => [
'slug' => 'slugs',
'url' => 'urls',
],

'register_fallback' => env('URL_REGISTER_FALLBACK', true),

'fallback_middleware' => [
'web',
],
];

Configuration Options

OptionTypeDefaultDescription
tables.slugstring'slugs'Table name for slugs
tables.urlstring'urls'Table name for URLs
register_fallbackbooltrueWhether to register the fallback route
fallback_middlewarearray['web']Middleware stack for fallback route

Next Steps

Now that you have Laravel URL installed, you can:

Troubleshooting

Migration Errors

If you encounter migration errors, ensure:

  • Your database connection is properly configured
  • You have sufficient database permissions
  • No conflicting table names exist

Fallback Route Issues

If the fallback route doesn't work:

  • Check that register_fallback is set to true
  • Verify middleware configuration
  • Ensure routes are loaded after package service provider