Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复 JsonResource 响应类型判断条件 #59

Merged
merged 1 commit into from
Nov 12, 2021
Merged

修复 JsonResource 响应类型判断条件 #59

merged 1 commit into from
Nov 12, 2021

Conversation

guanguans
Copy link
Contributor

laravel 8.58.0 版本没有 Illuminate\Http\Resources\Json\Resource 类,而是 \Illuminate\Http\Resources\Json\JsonResource

@jiannei jiannei merged commit 30d4389 into jiannei:main Nov 12, 2021
@jiannei
Copy link
Owner

jiannei commented Nov 12, 2021

问题可能是你安装的版本原因,Laravel 8 需要安装 4.0 以上版本,相关发版说明:https://github.com/Jiannei/laravel-response/releases/tag/v4.0.0

关于 Api Resource 的疑惑:Laravel 5.5.* 是Illuminate\Http\Resources\Json\Resource,在 Laravel 6 以后变更成了 \Illuminate\Http\Resources\Json\JsonResource, 可以查看compatibility/L-5.5 中对这种情况的兼容处理。
https://github.com/Jiannei/laravel-response/blob/a6c5f30c8509893a4a9df91de1918568db5a8d93/src/Response.php#L17

所以,对于原先 laravel 8 种使用了 laravel-repsone 的 1.* 中可能遇到的问题,升级下版本就解决了~

composer require jiannei/laravel-response "^4.0" -vvv
composer require jiannei/laravel-enum "^3.0" -vvv # 可选

@guanguans
Copy link
Contributor Author

guanguans commented Nov 15, 2021

@jiannei

我是在 1.x 版本用的,之前考虑到大版本升级后会有问题,问一下 1.x、2.x、3.x、4.x 版本都有什么大的区别?

@jiannei
Copy link
Owner

jiannei commented Nov 15, 2021

@jiannei

我是在 1.x 版本用的,之前考虑到大版本升级后会有问题,问一下 1.x、2.x、3.x、4.x 版本都有什么大的区别?

功能上没有区别。

2.x、3.x、是为了向下兼容 Laravel 6.、7.,1.x 版本的含义由原先支持 Laravel 8.* 变更成支持 Laravel 5.5,4.x 也就是支持现在的 Laravel 8.*。

@guanguans
Copy link
Contributor Author

@jiannei 好的,谢谢,那我升级 4.x 版本了。

@jiannei
Copy link
Owner

jiannei commented Apr 27, 2022

@all-contributors please add @guanguans for bug

@allcontributors
Copy link
Contributor

@jiannei

I've put up a pull request to add @guanguans! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants