Yêu cầu Oct 28th, 2019 1:07 a.m. 356 0 2
  • 356 0 2
0

Resource collection trong laravel có phải để format lại data?

Chia sẻ
  • 356 0 2

Các bác cho em hỏi về resource và resource collection với, làm sao để viết cho đúng chuẩn và áp dụng đúng? Em cảm ơn

2 CÂU TRẢ LỜI


Đã trả lời Oct 28th, 2019 1:12 a.m.
+3

Trên docs thì phần này có vẻ hơi ngắn. Bạn có thể tìm hiểu một số bài viết dưới đây.

  1. https://viblo.asia/p/phan-1-api-resources-laravel-5-XL6lAXeJZek
  2. https://viblo.asia/p/xay-dung-apis-bang-laravel-voi-eloquent-api-resources-m68Z0wQ9KkG Nhưng quan trọng nhất là bạn phải kết hợp làm ví dụ để hiểu hơn.

Còn nếu bạn có khả năng muốn tìm hiểu sâu thì có thể lên phần api của nó

  1. https://laravel.com/api/5.8/Illuminate/Http/Resources/Json/JsonResource.html
  2. https://laravel.com/api/5.8/Illuminate/Http/Resources/Json/Resource.html
  3. https://laravel.com/api/5.8/Illuminate/Http/Resources/Json/ResourceCollection.html
Chia sẻ
Avatar hieu nguyen @hieuhumg
Oct 30th, 2019 3:21 a.m.

cảm ơn bác

Đã trả lời Oct 28th, 2019 1:16 a.m.
+1

When building an API, you may need a transformation layer that sits between your Eloquent models and the JSON responses that are actually returned to your application's users. Laravel's resource classes allow you to expressively and easily transform your models and model collections into JSON.

document của laravel viết vậy. đúng là Resource collection hiểu nôm na là format data nhé

Chia sẻ
Avatar hieu nguyen @hieuhumg
Oct 30th, 2019 3:21 a.m.

cảm ơn bác

Viblo
Hãy đăng ký một tài khoản Viblo để nhận được nhiều bài viết thú vị hơn.
Đăng kí