TheValidatesRequeststrait now throws an instance ofIlluminate\Foundation\Validation\ValidationException instead of throwing an instance of Illuminate\Http\Exception\HttpResponseException. This is
unlikely to affect your application unless you were manually catching this exception.
Deprecations
The following features are deprecated in 5.2 and will be removed in the 5.3 release in June 2016: • Illuminate\Contracts\Bus\SelfHandlingcontract. Can be removed from jobs.
• Thelistsmethod on the Collection, query builder and Eloquent query builder objects has been renamed topluck. The method signature remains the same.
• Implicit controller routes usingRoute::controllerhave been deprecated. Please use explicit route registration in your routes file. This will likely be extracted into a package.
• Theget,post, and other route helper functions have been removed. You may use theRoute facade instead.
• The database session driver from 5.1 has been renamed to legacy-database and will be removed. Consult notes on the “database session driver” above for more information.
• TheStr::randomBytesfunction has been deprecated in favor of therandom_bytesnative PHP function.
• The Str::equals function has been deprecated in favor of the hash_equals native PHP function.
• Illuminate\View\Expressionhas been deprecated in favor ofIlluminate\Support\HtmlString.
Upgrading To 5.1.11 {#upgrade-upgrade-5.1.11}
Laravel 5.1.11 includes support forauthorizationandpolicies. Incorporating these new features into your existing Laravel 5.1 applications is simple.
Note: These upgrades are optional, and ignoring them will not affect your application.
Create The Policies Directory
Create / Register The AuthServiceProvider & Gate Facade
Create aAuthServiceProvider within yourapp/Providersdirectory. You may copy the contents of the default provider from GitHub¹⁵. Remember to change the provider’s namespace if your application is using a custom namespace. After creating the provider, be sure to register it in your app.phpconfiguration file’sprovidersarray.
Also, you should register theGatefacade in yourapp.phpconfiguration file’saliasesarray: 1 'Gate' => Illuminate\Support\Facades\Gate::class,
Update The User Model
Secondly, use theIlluminate\Foundation\Auth\Access\Authorizabletrait andIlluminate\Contracts\Auth\Access\Authorizable contract on yourApp\Usermodel:
1 <?php 2 3 namespace App; 4 5 use Illuminate\Auth\Authenticatable; 6 use Illuminate\Database\Eloquent\Model; 7 use Illuminate\Auth\Passwords\CanResetPassword; 8 use Illuminate\Foundation\Auth\Access\Authorizable;
9 use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; 10 use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract; 11 use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract; 12
13 class User extends Model implements AuthenticatableContract,
14 AuthorizableContract,
15 CanResetPasswordContract
16 {
17 use Authenticatable, Authorizable, CanResetPassword;
18 }
Update The Base Controller
Next, update your baseApp\Http\Controllers\Controllercontroller to use theIlluminate\Foundation\Auth\Access\AuthorizesRequests trait:
1 <?php
2
3 namespace App\Http\Controllers; 4
5 use Illuminate\Foundation\Bus\DispatchesJobs;
6 use Illuminate\Routing\Controller as BaseController; 7 use Illuminate\Foundation\Validation\ValidatesRequests; 8 use Illuminate\Foundation\Auth\Access\AuthorizesRequests; 9
10 abstract class Controller extends BaseController
11 {
12 use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
13 }
Upgrading To 5.1.0 {#upgrade-upgrade-5.1.0}
Estimated Upgrade Time: Less Than 1 HourUpdate
bootstrap/autoload.phpUpdate the$compiledPathvariable inbootstrap/autoload.phpto the following: 1 $compiledPath = __DIR__.'/cache/compiled.php';
Create
bootstrap/cacheDirectory
Within yourbootstrapdirectory, create acachedirectory (bootstrap/cache). Place a.gitignore file in this directory with the following contents:
1 *
2 !.gitignore
This directory should be writable, and will be used by the framework to store temporary optimiza- tion files likecompiled.php,routes.php,config.php, andservices.json.
Add
BroadcastServiceProviderProvider
Within yourconfig/app.phpconfiguration file, addIlluminate\Broadcasting\BroadcastServiceProvider to theprovidersarray.
Authentication
If you are using the providedAuthControllerwhich uses theAuthenticatesAndRegistersUsers trait, you will need to make a few changes to how new users are validated and created.
First, you no longer need to pass theGuardandRegistrarinstances to the base constructor. You can remove these dependencies entirely from your controller’s constructor.
Secondly, the App\Services\Registrar class used in Laravel 5.0 is no longer needed. You can simply copy and paste your validator and create method from this class directly into your AuthController. No other changes should need to be made to these methods; however, you should be sure to import theValidatorfacade and yourUsermodel at the top of yourAuthController. Password Controller
The includedPasswordControllerno longer requires any dependencies in its constructor. You may remove both of the dependencies that were required under 5.0.
Validation
If you are overriding theformatValidationErrorsmethod on your base controller class, you should now type-hint theIlluminate\Contracts\Validation\Validatorcontract instead of the concrete Illuminate\Validation\Validatorinstance.
Likewise, if you are overriding theformatErrorsmethod on the base form request class, you should now type-hint Illuminate\Contracts\Validation\Validator contract instead of the concrete Illuminate\Validation\Validatorinstance.
Eloquent
ThecreateMethod
Eloquent’s create method can now be called without any parameters. If you are overriding the createmethod in your own models, set the default value of the$attributesparameter to an array:
1 public static function create(array $attributes = [])
2 {
3 // Your custom implementation
4 }
ThefindMethod
If you are overriding thefindmethod in your own models and callingparent::find()within your custom method, you should now change it to call thefindmethod on the Eloquent query builder:
1 public static function find($id, $columns = ['*'])
2 {
3 $model = static::query()->find($id, $columns); 4
5 // ...
6
7 return $model;
8 }
ThelistsMethod
Thelistsmethod now returns aCollectioninstance instead of a plain array for Eloquent queries. If you would like to convert theCollectioninto a plain array, use theallmethod:
1 User::lists('id')->all();
Be aware that the Query Builderlistsmethod still returns an array. Date Formatting
Previously, the storage format for Eloquent date fields could be modified by overriding the getDateFormat method on your model. This is still possible; however, for convenience you may simply specify a$dateFormatproperty on the model instead of overriding the method.
The date format is also now applied when serializing a model to anarrayor JSON. This may change the format of your JSON serialized date fields when migrating from Laravel 5.0 to 5.1. To set a specific
date format for serialized models, you may override theserializeDate(DateTime $date)method on your model. This method allows you to have granular control over the formatting of serialized Eloquent date fields without changing their storage format.