Тёмный
No video :(

Laravel API Resources: 3 More Complex Examples 

Laravel Daily
Подписаться 143 тыс.
Просмотров 25 тыс.
50% 1

Опубликовано:

 

22 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 55   
@JohnToridas
@JohnToridas 2 года назад
as far as i understand, resources are a mechanism to represent models, in other words transform model data for json api response, and by doing that we can take away code from controllers and make controllers more clear
@cristianbilu
@cristianbilu 2 года назад
Yep, you got it, also it makes this reusable code, so you can use it in many parts of a controller using the eager load methods presented in the first example
@yashpatel7291
@yashpatel7291 2 года назад
when I see your video. I am feeling like improve to the next level in Laravel ❤
@chazzman4553
@chazzman4553 2 года назад
Useful, no BS, straight to the point👍
@GergelyCsermely
@GergelyCsermely 2 года назад
Yes, I'm using it since I learned from Your course and free RU-vid videos. It is really cool. Thanks for this video too,
@anything_goes24
@anything_goes24 2 года назад
Your explanation is very APT and very understanding..
@pintu6006
@pintu6006 2 года назад
I use resources for api response. Btw love your work and dedication on explaining minute details in laravel which most others don't know about.
@joshbarros1995
@joshbarros1995 2 года назад
I love these API videos!!!
@user-qc2um7sn1y
@user-qc2um7sn1y 2 года назад
Thank you for this video. On my point, resources very helpfull feature. I use them all time during development application, becouse it helps me keep my code cleanest and clearer. And, of course, resources help me more flexible creating response formats
@ammarqureshi3215
@ammarqureshi3215 2 года назад
If returning data with a laravel api takes 637 ms the same size of data in lumen it takes 150 ms . so i prefer to do it with lumen i hope if there could be a way to remove all the extra features from laravel in a api response to increase the speed.
@wailantirajoh3052
@wailantirajoh3052 2 года назад
in some case, when we only need to transform some data in one place, we can do without creating another api resource class like this User::paginate(10) ->through(function ($user) { return [ 'id' => $user->id, 'name' => $user->name, 'email' => $user->email, 'image' => $user->image ]; });
@raimonds.L
@raimonds.L 2 года назад
I'd rather have 1 liner in the controller + Resource class
@wailantirajoh3052
@wailantirajoh3052 2 года назад
@@raimonds.L its personal preferences, sometimes i just dont like many class when apps get bigger, and have many class that only used 1 time its just not really necessary
@martomystery
@martomystery 2 года назад
Doesn't this remove the pagination info from your result?
@Viveksharmaa
@Viveksharmaa 2 года назад
I use API resources and it is awesome.
@ShailendraSharmaDark
@ShailendraSharmaDark 2 года назад
what is API resources?
@Viveksharmaa
@Viveksharmaa 2 года назад
@@ShailendraSharmaDark in simple words API Resource is used to format the API response data only.
@marxrizld9317
@marxrizld9317 2 года назад
@@Viveksharmaa so what's the benefit instead of simply using controller with response()->json($data) ?
@salimedia33
@salimedia33 2 года назад
Love this kind of Videos ;) Thanks
@sirajul-anik
@sirajul-anik 2 года назад
Not much SRP expert, but is it a good idea to delegate the reversion @ 2:23 and other complex things to separate methods?
@gabrielnzete8913
@gabrielnzete8913 2 года назад
Resource was not well thought out .... if you do c# net core precisely... you will know that a simple return class will do all these bulky things faster and more cleaner
@luizmeier
@luizmeier 2 года назад
Well explained.
@genephillip4233
@genephillip4233 2 года назад
what`s your thought sir with timcdonald json API resource
@giacomogaravaglia6742
@giacomogaravaglia6742 2 года назад
I was using this approach today and I found something strange related this topic and response macro (another of your video). If you use api resource (collection) with pagination and response macro, the pagination data, like links, desappear from the response content. Can you reproduce this bug?
@mohammadazzam5265
@mohammadazzam5265 2 года назад
Hello Mr.Povilas, I have a minor question if you may... Is it a good practice to shuffle or reconstruct an array using resources API? And if no what do you recommend other than some complex algorithms?
@LaravelDaily
@LaravelDaily 2 года назад
Not sure what exactly you mean by complex algorigthms, need examples. But probably, complex algorithms like require complex solutions, more than default API resources.
@mohammadazzam5265
@mohammadazzam5265 2 года назад
@@LaravelDaily well it might not be complex, just reorganizing the array to another form or combining between two arrays in a specific order. Knowing that it is just a regular controller that will pass the data to a view and not an API response. So is using resources a good practice or should we for example use collections
@LaravelDaily
@LaravelDaily 2 года назад
You can use collections inside resources, it's not either-or
@mohammadazzam5265
@mohammadazzam5265 2 года назад
@@LaravelDaily so using resources for arrays is a good practice in laravel right ?
@LaravelDaily
@LaravelDaily 2 года назад
There's no good or bad practice. Yes, you can do that, or you can do it in a different way. There's no only way, it's personal preference.
@SohailKhan-yy2xc
@SohailKhan-yy2xc 2 года назад
I'm looking for solution.. how can we search database on the basis of relationship.. like i have a situation.. a field technology and other is version.. both has different tables and the pivot.. i want to search a technology with specific version if exists in relation
@LaravelDaily
@LaravelDaily 2 года назад
Wherehas() method probably
@raimonds.L
@raimonds.L 2 года назад
I'm building SPA. 99% goes through Requests and returns through Resource
@leslysuarez9686
@leslysuarez9686 2 года назад
Excuse me, Povilas, If I wanted to deploy my API, is heroku an option? Because I did it and it generated my url, but I can't test it in postman
@LaravelDaily
@LaravelDaily 2 года назад
I haven't tried Heroku myself. I use Digital Ocean with Laravel Forge, mostly.
@afiqhamzah2463
@afiqhamzah2463 2 года назад
API resource is used to transform data when sending the data to clients, but can API resource transform data that is received from external API call?
@LaravelDaily
@LaravelDaily 2 года назад
No
@afiqhamzah2463
@afiqhamzah2463 2 года назад
@@LaravelDaily any advice on how to transform API responses to be more eloquent/collection like?
@LaravelDaily
@LaravelDaily 2 года назад
collect($array);
@gabrielnzete8913
@gabrielnzete8913 2 года назад
I just feel using resource is a long thing... it's better you create a return class and map whatever you need to send to the api from the parents. ... this is one of the reason c# net core api is faster. Using resource is bulky
@bboydarknesz
@bboydarknesz 2 года назад
I rarely use this, but this looks very complex man 😬
@LaravelDaily
@LaravelDaily 2 года назад
What do you use instead? Or you don't need to transform your API returns like this?
@pintu6006
@pintu6006 2 года назад
It is really easy. You just need to create array for the data that you need to send in your json response.
@Viveksharmaa
@Viveksharmaa 2 года назад
In my initial projects I did not use it because it was supposed to hard for me but when I decided to learn and implement, it was more simpler then I thought.
@bboydarknesz
@bboydarknesz Год назад
I am back, and I use resources now because of complex API I take back my words :)
@laayounelive2020
@laayounelive2020 2 года назад
Is good to use resource in web and blade not only in Api ?
@LaravelDaily
@LaravelDaily 2 года назад
I don't see the use for this, after all they are called API resources for a reason.
@jetferret
@jetferret 2 года назад
What is your take on the Spatie/laravel-fractal and Dingo/API packages? I use them for larger projects.
@LaravelDaily
@LaravelDaily 2 года назад
Since API resources appeared in Laravel 5.5, I don't feel any need for any external packages. But if they work for you, great, keep using them.
@hyouhiro2366
@hyouhiro2366 2 года назад
thanks for great videos, Mr. Korop. i would like you kindly ask you, if you have a time, to teach laravel function. When I read code of my company Laravel Project, one is coding new User , and another is app(User::class) for getting new instance. what is wrong new xxxx and app(xxxx::class) ? what is using properly? if you talk about anything, very happy!
@LaravelDaily
@LaravelDaily 2 года назад
I don't remember using app() for new class instance, I always use new. Maybe there's a slight difference, I don't remember it by heart.
@hyouhiro2366
@hyouhiro2366 2 года назад
@@LaravelDaily thanks for reply, Mr ! I will be don't worry about the little things.
2 года назад
@@hyouhiro2366 That’s Three Little Birds by Bob Marley.
@SahilSharma-ws1oz
@SahilSharma-ws1oz 2 года назад
🥇 first
Далее
Laravel Junior Code Review: 12 Tips on Everything
15:30
Faster Eloquent: Avoid Accessors with Foreach
9:35
Просмотров 53 тыс.
ОБЗОР ПОДАРКОВ 🎁 | WICSUR #shorts
00:55
💀СЛОМАЛ Айфон за 5 СЕКУНД😱
00:26
Eloquent Performance: TOP 3 Mistakes Developers Make
7:59
Laravel: Repository Pattern in practice
27:13
Просмотров 11 тыс.
The Logging Everyone Should Be Using in .NET
15:34
Просмотров 59 тыс.
Nothing is really cool in Kotlin
7:43
Просмотров 2,5 тыс.
Laravel: Create Public API with Cache and Rate Limits
12:18
ОБЗОР ПОДАРКОВ 🎁 | WICSUR #shorts
00:55