Комментарии:
How about fetching more data, after initial page view, is it then a regular API call?
ОтветитьHot to handle pagination with JsonResource?
Ответить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(),
];
})
]);
Returning JSON resource! Fantastic, Pov. Great tip. Roll on 100k subscribers. You deserve it.
Ответить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
Ответить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.
ОтветитьI think this is a nice option to limit content
Str::limit
new concept is cleared. thank you sir.
Ответить