Junior Code Review: Simple Laravel API - in 5 Different Ways

preview_player
Показать описание
I've given a task to my students to create two simple API endpoints in Laravel. Let's see how they did and what advice I can give to them.

- - - - -
Support the channel by checking out our products:
Рекомендации по теме
Комментарии
Автор

If you are shown and evaluated different ways of solving the problem, you can learn even more. Really a good idea.

UliGer
Автор

From my recent experience when writing the list you only want to explicitly load the columns you need to save some memory usage as it can quickly add up with large lists, especially if you aren't using server-side pagination.
You can also save additional memory usage and database traffic by using LEFT JOIN authors and SELECT GROUP_CONCAT on authors' name if all you need is a comma separated list of their names, something like this:

Books::select('id', 'name', 'price', 'cover', ", authors.first_name, authors.last_name)) SEPARATOR ", " AS author_name')
->get()

JonathanKingstonFear
Автор

8:43 whenAppended is just a condition, whether to return a VALUE of description or not. Description will be returned for book list as well but will always be empty, which is very confusing and wrong.
I'd add that the only correct way in my opinion is with merging arrays, since field 'description' will not be returned if you access a list of books.

poplach
Автор

This is great! Really useful. Perhaps a video before showing the task, so people can try and follow along as well? Then an example of how you'd do it?

NathanBudd
Автор

Great teacher && Great explanation... Useful as always
Many thanks.

nazeerkaadan
Автор

great video, Changing RouteServiceProvider just to add v1 can break other API code because it will change all routes in api file to use v1

HussamAdil
Автор

The way you teach is very spectacular.

blessdarah
Автор

apiresource this is something new which i have learn today thank you. will apply it in my next project

dollerbill
Автор

Incredible content, thank you!
Its hard to find API content on brazilian courses

josuebarros-desenvolvedorw
Автор

Nice video as usual. Thank you for sharing your knowledge!

hatsushiroyuki
Автор

Great video, very didactic the comparing of different possible solutions to the same problem

phil_
Автор

it's awesome code, thanks for your efforts, keep doing that

josetovarrodriguez
Автор

I don't even know php and Lavarel, but these reviews and notes are really usefull! I'm interessed in starting learning the language based on your review videos!

olenstriker
Автор

Thank u very nice examples one can leqrn from each something

shire
Автор

Great informative video as always. Please do a video on lazy loading of images. It will be really helpful.

mianz
Автор

6:27 What if to add 'with' or even 'whenLoaded' inside BookResourceCollection instead of BookController

TsAex
Автор

First of all, I want to thank you for all the content that you share with the community. I have a question about the best way to version an API. How is the best structure to maintain different versions of an API. If you separate the Controllers and Resources into different folders, yo will have repetead code.

facundocondal
Автор

Hello, I tried using the API routes before (api.php), it works fine in my local development, But when I tried hosting it to cpanel, I got the Unauthorized or Unauthenticated error, I don't remember what it was exactly. All routes with middlware auth, cannot seem to be access. All routes response are Unauthenticated if I recall. Can't find any solution for that, so I moved all my API routes to Web routes instead and added a prefix of 'api'

Akosiyawin
Автор

If i was to have a user dashboard which is only accessible through a login, and i want the user to be able to display all their customers, add, edit and delete customers, would i put all these in the web route? or just put the 'display all' customers in the Api route and the rest in web?

AlexG-wknh
Автор

I normally do this: Books::select([specific columns only])->with('authors:id, name')->get(); or better use query builder with LEFT JOIN (faster than eloquent).

johnyonardpauly