dingo API 支持 Laravel5 和 Lumen 了,速去围观。

分享 jinqibu ⋅ 于 3年前 ⋅ 最后回复由 fantiq 2年前 ⋅ 17562 阅读




Hello all, I've recently pushed quite a number of changes to the develop branch that allows you to use this package in your Lumen and Laravel 5 apps.

You can require it using 0.9.*@dev.

Please note that if you're using Lumen you'll need to be using lumen-framework 5.0.*@dev for it to work correctly. These several routing changes that are yet to make it to a stable Lumen release.

A few things to note...

Much of the configuration can be done via environment variables now. You can still publish the config file in Laravel 5 and make changes that way. Lumen will require you to use the environment variables. For things that can't be set with environment variables there will be a method available on the underlying instance to change whatever it is you need.
There is no internal dispatcher at this point in time. I was focusing on the core of the API for now to make that that's all sweet before moving on to the internal dispatcher.
There is no route command at this point in time. It will be back.
There is no URL generator at this point in time. it will be back.
There's no facade at the moment. You will need to get an instance of the API router (app('api.router')) to register your routes.
Here is a very quick sample of how it's now used. In your Lumen bootstrap/app.php file you'd register the Lumen provider.


// Get an instance of the API router so we can use it in the routes.php file
 $api = $app['api.router'];

Now we can register our routes in the routes.php file.

$api->version('v1', function ($api) {
    $api->resource('users', 'UserController');

All routing methods available in L5 are available in both L5 and Lumen. This includes standard routing with get, post, etc, as well as resource and controller routes.

You can also setup group options much like in previous options (there is also an $api->group() method).

$api->version('v1', ['namespace' => 'App', 'protected' => true], function ($api) {
   $api->resource('users', 'UserController');

Aside from that not a whole lot has changed but there are a few new things that I'll be talking about over time. For now, I'd love it if people could give it a whirl and let me know if they come across any issues. I'll iron things out as quick as I can.


本文章首发在 Laravel China 社区
回复数量: 1

Composer 中国全量镜像

Top 250 扩展包

Lumen 中文文档

Laravel 速查表

Laravel 中文文档

Laravel 项目开发规范

Laravel 开发环境部署

Composer 中文文档

Elasticsearch-PHP 中文文档

Lumen 中文文档

GraphQL PHP 中文文档


TDD 构建 Laravel 论坛笔记

PHP PSR 标准规范

PHP 设计模式全集

Dingo API 中文文档