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

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

Laravel Daily

3 года назад

76,247 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Rodrigo Nishino
Rodrigo Nishino - 15.11.2022 23:05

Very nice thank you

Ответить
Zuhril Fahrizal
Zuhril Fahrizal - 27.10.2022 15:38

Thanks for tutorials 🙏

Ответить
Phil86
Phil86 - 24.07.2022 14:41

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

Ответить
Abderrahman Fodili
Abderrahman Fodili - 19.07.2022 19:10

You come across as a harsh tutor 😅 but this review made me feel better about my skills

Ответить
SXsoft99
SXsoft99 - 17.05.2022 19:17

what i haven't noticed any of your students do is select only what fields are needed for listing
if you dont need a certain field dont use select(*), since a description db column might have 3k characters, and you only needed that field on your details page

Ответить
Martin Feldman
Martin Feldman - 16.03.2022 05:37

This is a great video!

Ответить
Hafiz shaheed
Hafiz shaheed - 15.02.2022 20:43

How can I use web's guard and api's guard both in laravel project?

Ответить
Facundo Condal
Facundo Condal - 26.01.2022 21:40

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.

Ответить
Alex G
Alex G - 24.10.2021 14:31

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?

Ответить
Aadhil....!
Aadhil....! - 21.10.2021 12:14

Ad 25..serch..?

Ответить
mhamad awwad
mhamad awwad - 31.08.2021 09:31

Hello, can I send you a code I wrote and give me your opinion on it
Thank you ❤️❤️

Ответить
bless darah
bless darah - 20.08.2021 00:29

The way you teach is very spectacular.

Ответить
Deka Thomas
Deka Thomas - 20.07.2021 08:46

Hello, could I join the junior developer community program?

Ответить
Josue Barros - Desenvolvedor Web
Josue Barros - Desenvolvedor Web - 17.07.2021 21:46

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

Ответить
Vinit Kumar
Vinit Kumar - 16.07.2021 07:02

Hi poli, How to make a Website and API REST with the same Controllers? It is possible I'm totally confused, and how to create both are same Controllers, plz help

Ответить
M.Batbaatar
M.Batbaatar - 14.04.2021 19:27

Really helpful thanks

Ответить
Rodrigo Santos
Rodrigo Santos - 15.03.2021 19:47

great tips!! :D

Ответить
Timo
Timo - 14.03.2021 02:48

No one got the /api/v1 properly right IMHO. What I would do is close to your favorite implementation but instead of modifying the global prefix for the api routes from api to api/v1 I'd still introduce a route group wrapping the Route::apiResource(...).
The reasoning is simple: What are you going to do when you have to implement api v2? Create a custom apiv2.php route file and load it in your Route-SP? I hope you see where I'm going with this.

Ответить
Yang Du
Yang Du - 11.03.2021 18:27

You‘re a rock star in tech world

Ответить
KELVEZU
KELVEZU - 01.03.2021 12:20

Some of the methods discussed here was not in the documentation. As a beginner in Laravel, should I buy premium courses just to unlock these secret methods?

Ответить
John Biggs
John Biggs - 01.03.2021 10:45

Hi,

Where did your students take this course? How can I register for this?

Thanks

Ответить
_passby
_passby - 01.03.2021 03:54

Good video

Ответить
The Dev Trucker
The Dev Trucker - 28.02.2021 23:40

Wouldt be a better practice to keep the resource the dummiest as possible, and condition him with something like $this->when(Arr::exists($this, 'description'), $this->description ?? '') and then you just pick the data you want in the list and in the view?
Seems like a better approach to give the resource the logic to only work with we give to him (and it be his only concern, even ignoring the existance of the request), and control our business logic in a better place like controller.

Ответить
olenstriker
olenstriker - 28.02.2021 21:03

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!

Ответить
John Yonard Pauly
John Yonard Pauly - 28.02.2021 20:41

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).

Ответить
shire
shire - 28.02.2021 20:33

Thank u very nice examples one can leqrn from each something

Ответить
shire
shire - 28.02.2021 20:26

I didn't know about the apiResource

Ответить
João Oliveira
João Oliveira - 28.02.2021 19:50

Route::resource for me is a no go. You are using a resource to then use only two methods. That only makes things harder IMO. You lose control of the naming and you don't see the whole picture when scanning the route file.

Ответить
100 doller bill
100 doller bill - 28.02.2021 17:44

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

Ответить
jose tovar rodriguez
jose tovar rodriguez - 28.02.2021 17:17

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

Ответить
Salim Mammadov
Salim Mammadov - 28.02.2021 16:54

Awesome ! Can you make a video about how to make filter searching by the shortest way?
Example :
if ($request->cid != null) {
$equ->where('category_id', $request->cid);
}
if ($request->mid != null) {
$equ->where('model_id', $request->mid);
}
$result = $equ->paginate(15);

return response()->json($result);
}

Ответить
supra m941g
supra m941g - 28.02.2021 16:17

web.php or api.php it is not about route path (or right naming), it is about middlewares for request , obviously you didn't explain it to your students, and don't explain it in video.
sad.

Ответить
iedi3
iedi3 - 28.02.2021 15:14

Hi guys, i keep seeing the statement “new Resource($book)”. Is there a way to avoid the “new” statement and use Dependency Injection in some way?

Ответить
Nathan Budd
Nathan Budd - 28.02.2021 14:41

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?

Ответить
Hussam Adil
Hussam Adil - 28.02.2021 13:37

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

Ответить
Alexander Anastasiadis
Alexander Anastasiadis - 28.02.2021 12:56

Is correct to create api through WEB instead API route file?
And what are the differences

Ответить
pk bissyer
pk bissyer - 28.02.2021 12:40

Sir,Make a video on shipping api used in laravel any project such as ecommerce etc.

Ответить
Uli2000Ger
Uli2000Ger - 28.02.2021 11:17

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

Ответить
yayin
yayin - 28.02.2021 11:14

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'

Ответить
Nazeer Kaadan
Nazeer Kaadan - 28.02.2021 10:18

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

Ответить
Jon KF
Jon KF - 28.02.2021 10:13

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', DB::raw('GROUP_CONCAT(CONCAT_WS(" ", authors.first_name, authors.last_name)) SEPARATOR ", " AS author_name')
->get()

Ответить
code with tee
code with tee - 28.02.2021 09:51

Thanks, for this tip

Ответить
Alejandro Valenzuela
Alejandro Valenzuela - 28.02.2021 09:49

Gracias, genial el video!!

Ответить
Hatsu Shiroyuki
Hatsu Shiroyuki - 28.02.2021 09:48

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

Ответить
Moumouni Narey
Moumouni Narey - 28.02.2021 09:33

Great video, thank's

Ответить