Vue Inertia + Laravel Course. 3/17: API Resources in Inertia

Vue Inertia + Laravel Course. 3/17: API Resources in Inertia

Laravel Daily

2 года назад

22,004 Просмотров

This lesson is about the fact that you can still use API resources, even though technically it's not API.

Get the full course to get the code repository: https://laraveldaily.teachable.com/p/practical-vue-inertia-laravel-from-scratch

- - - - -
Support the channel by checking out our products:
- Enroll in my Laravel courses: https://laraveldaily.teachable.com
- Try our Laravel QuickAdminPanel: https://bit.ly/quickadminpanel
- Buy my ready-made Laravel scripts: https://laraveldaily.gumroad.com
- Purchase my Livewire Kit: https://livewirekit.com
- Subscribe to my weekly newsletter: http://bit.ly/laravel-newsletter
Ссылки и html тэги не поддерживаются


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

@jargolauda2584
@jargolauda2584 - 03.01.2023 22:23

How about fetching more data, after initial page view, is it then a regular API call?

Ответить
@MassimoSimonini
@MassimoSimonini - 19.04.2022 10:24

Hot to handle pagination with JsonResource?

Ответить
@BrnBar
@BrnBar - 01.04.2022 23:58

I think we could do this directly inside a controller also;

return Inertia::render('Posts/Index', [
'posts' => Post::all()->map(function ($post) {
return [
'id' => $post->id,
'title' => $post->title,
'content' => substr($post->content, 0, 50).'...',
'created_at' => $post->created_at->toDateString(),
];
})

]);

Ответить
@rosselliot8971
@rosselliot8971 - 31.03.2022 09:45

Returning JSON resource! Fantastic, Pov. Great tip. Roll on 100k subscribers. You deserve it.

Ответить
@TahirBhai
@TahirBhai - 31.03.2022 08:17

Assume you have 20 columns in a table of 'Posts' then doing Post::all() inside the PostResource() is still selecting all columns in later in the PostResource() you then select 3 columns. So the question model first loads all 20 columns and 3 columns to show. How to avoid loading 20 columns in first place, still we should use SELECT() ? or its already handle using Resource API

Ответить
@KastsEcho
@KastsEcho - 30.03.2022 16:41

One new helper you could use in Laravel 9 is to_route(), which is functionally the same as redirect()->route() and accepts the same parameters. The only difference is how cleaner it reads in code.

Ответить
@ruslanpopelyshyn1277
@ruslanpopelyshyn1277 - 30.03.2022 10:57

I think this is a nice option to limit content
Str::limit

Ответить
@agun21st
@agun21st - 30.03.2022 08:20

new concept is cleared. thank you sir.

Ответить