What Is New in Laravel 3.1
Laravel 3.1 introduces a set of focused enhancements and fixes to refine the framework's core functionality. This update brings new database seeding capabilities, improved validation rules, and several quality-of-life improvements for developers.
| Category | Key Changes |
|---|---|
| New Features | Database Seeding, New Validation Rules, Artisan Enhancements |
| Improvements | Session Driver Flexibility, Pagination, Configuration Loading |
| Bug Fixes | Routing, Database, Validation, and View Rendering Issues |
| Deprecated | Legacy Autoloader Support |
What new database features were added?
The standout addition is a database seeder, which is a huge time-saver for populating your development database with test data. You can now use the new Artisan command db:seed to run all your seed classes.
In practice, this means you define a Seeder class and then call it from the laravel.php config file. This makes setting up a consistent testing environment much more straightforward compared to manual seeding.
How did validation get better?
Validation received two new rules: alpha_num and alpha_dash. The alpha_num rule ensures a field contains only letters and numbers, while alpha_dash allows letters, numbers, dashes, and underscores.
This matters because it handles common validation scenarios out-of-the-box. You no longer need to use a regex for these simple but frequent checks, making your form validation code cleaner and more readable.
What improvements were made to sessions?
The framework now supports using a cookie driver for sessions. This is a lightweight option for sessions that don't require server-side storage, which can be perfect for certain low-overhead applications.
Additionally, the APC session driver was fixed to properly support the new session payload structure, resolving issues where session data might not be saved correctly.
Were there any routing fixes?
Yes, a significant fix was applied to the routing system. The router now correctly handles controller routes that contain hyphens, which was a known issue in previous versions that would cause routes to fail.
This is a practical fix for developers who prefer using hyphenated URLs for SEO or readability purposes. Your routes like user-profile will now work as expected when pointing to a controller.
What about the view layer?
Several view-related bugs were squashed. The pagination views now correctly render even when no results are present, preventing potential errors. The View::name() method was also fixed to work properly.
On the configuration side, the framework now loads all configuration files when the application starts. This prevents a bug where sometimes config values from different files wouldn't be available when needed.
FAQ
How do I use the new database seeder?
Create a class that extends Laravel\Database\Seeder and define a run() method. Then, register your seeder class in the laravel.php configuration file under the seeds key. Finally, run php artisan db:seed from the command line.
What was the issue with the old autoloader?
Support for the legacy Autoloader (from Laravel 3.0) has been deprecated. This was done to streamline the codebase and encourage the use of the newer, more efficient autoloading mechanism. You should update your application to avoid using the deprecated class.
Does the cookie session driver encrypt data?
The release notes do not specify encryption for the cookie session driver. In practice, you should assume session data stored in cookies is not encrypted by default in this version, so avoid storing sensitive information with this driver.
Were there any changes to the Query class?
Yes, a bug was fixed where the insert_get_id() method would sometimes fail on PostgreSQL databases. This ensures consistent behavior when inserting records and retrieving their IDs across different database systems.
Is there a new way to manage assets?
While not a new feature, a bug was fixed in the Asset::container() method. It now correctly handles the container name, preventing issues when managing multiple asset containers within a single application.