[Lumen5.2 documentation] getting started-Upgrade guide

Source: Internet
Author: User
[Lumen5.2 documentation] getting started -- Upgrade guide Lumen5.2 only focuses on providing stateless APIs. Therefore, the session has been removed from the framework. if you want to use the session, you need to switch to Laravel 5.2.

Upgrading from Lumen 5.2 to Laravel 5.2 is simple. you only need to copy the classes written in the routes and applications to Laravel. because Laravel and Lumen share many underlying components, even a self-compiled class does not require major changes.

1. upgrade dependencies

Update the composer. json file to point to laravel/lumen-framework 5.2 .*

2. Application

Lumen no longer implements the Illuminate \ Contracts \ Foundation \ Application contract. any declarations of this type of dependency must be updated to directly reference the Laravel \ Lumen \ Application class.

Authentication

Because Lumen no longer supports sessions, authentication is based entirely on API tokens or request headers. For the implementation and use of Lumen authentication, see the complete authentication documentation.

Set3. base classes of the Eloquent set

The Eloquent Collection instance now returns a Collection base class (Illuminate \ Support \ Collection) to provide the following methods: pluck, keys, zip, collapse, flatten, flip.

Retain Key

The slice, chunk, and reverse methods can now retain the keys in the set. if you do not want these methods to retain the keys, you can use the values method on the Collection instance.

4. DatabasesMySQL date

Starting from MySQL 5.7, 0000-00-00 00:00:00 is no longer considered a valid date, because the strict mode is enabled by default, all timestamp fields must receive a valid default value when inserting records into the database. you can use the useCurrent method to set the timestamp field to the current timestamp by default during migration, or call the nullable method to allow null values:

$table->timestamp('foo')->nullable();$table->timestamp('foo')->useCurrent();$table->nullableTimestamps();
MySQLJSON field type

MySQL 5.7 and later versions support json fields, so the json field type can now create a json field and save it to the database. if MySQL version is earlier than 5.7, you need to use the text field to save json data to this field.

5. EloquentDate conversion

All attributes marked as date or datetime added to $ casts will be converted to strings when the toArray method on the model or set is called, this is consistent with the date conversion defined in the $ dates array.

Global scope

The implementation of the global scope is rewritten to make it easier to use. the remove method is no longer required for the global scope. Therefore, if you call this method in your code, you need to remove it.

If you call the getQuery method on the Eloquent query builder to access the underlying query builder instance, you need to change it to toBase.

If you call the remove method, you need to change it to $ eloquentBuilder-> withoutGlobalScope ($ scope ).

The withoutGlobalScope and withoutGlobalScopes methods are added to the Eloquent Query builder. all calls to the $ model-> removeGlobalScopes ($ builder) method need to be changed to the simpler $ builder-> withoutGlobalScopes () method ().

Primary key

By default, Eloquent assumes that your primary key is an integer and is automatically converted to an integer. to set any primary key that is not an integer, set the value of $ incrementing on the Eloquent model to false:

/** * Indicates if the IDs are auto-incrementing. * * @var bool */public $incrementing = true;
6. Exception handling

The $ dontReport attribute of the App \ Exceptions \ Handler class must include at least the following types of Exceptions:

use Illuminate\Validation\ValidationException;use Illuminate\Auth\Access\AuthorizationException;use Illuminate\Database\Eloquent\ModelNotFoundException;use Symfony\Component\HttpKernel\Exception\HttpException;/** * A list of the exception types that should not be reported. * * @var array */protected $dontReport = [    AuthorizationException::class,    HttpException::class,    ModelNotFoundException::class,    ValidationException::class,];
7. IronMQ

IronMQ queue driver is now transferred to its own package, the core framework does not include its processing, to use IronMQ, see: http://github.com/LaravelCollective/iron-queue

8. storage

If you use Laravel's Flysystem, you need to register filesystem binding and add the following code to bootstrap/app. php:

$app->singleton('filesystem', function ($app) {    return $app->loadComponent(        'filesystems',        Illuminate\Filesystem\FilesystemServiceProvider::class,        'filesystem'    );});
9. verification

ValidatesRequeststrait used by the Lumen controller base class is now merged into ProvidesConvenienceMethodstrait.

If you previously used ValidatesRequeststrait outside the controller base class, you can copy it from the 5.1 branch or directly use ProvidesConvenienceMethodstrait.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.