You can still just make regular ajax calls with axios and pass to vue/react. I do this in a few places
Transferring data between back-end and front-end in Laravel-Inertia
Hi,
My question in a nutshell: “Is there a third way for transferring data between back-end and front-end except Inertia::render and shared data by HandleInertiaRequests? For just get some data from back-end without reload our Vue page again.”
My question in details: I watched Mr. Korop’s Laravel+Inertia full course in youtube (youtube com/watch?v=swelKdHlvco) and built that CRUD step by step and it worked perfectly. but I just think to myself, let make a really SAP CRUD and put all Create, Edit and Show in the Index page, just for practicing. I mean, a simple posts CRUD all in just 1 page.
So, I moved “create form” at the top of the index and it worked fine when adding new post, without refreshing page. but my problem is “edit page”.
My plan:
- I click on edit button (an edit form toggle out at top) ->
- Send post.id to back-end->
- Return full data (title, full content and writer) to front-end ->
- full data inserted in the edit form ->
- after submit edited data send to back-end
- ...
My problem is in step 3 and 4. in my posts controller:
public function edit(Request $request)
{
$post = Post::find($request->id);
return Inertia::render('Posts/Index', compact('post'));
}
If I return full data by Inertia::render to front-end so it doesn’t show my index list anymore. If I add "$posts = Post::all();" beside "$post"and send it to front-end it works but as performance view it's wrong because we shouldn't get posts list every time.
The correct way should be: posts list doesn't refresh, and just a post-id sent to back-end, then full post data return and placed in edit form. that's it.
Are there other ways except Inertia::render and "shared data" for sending data between front-end and back-end needless to get all posts from db and send it again to front-end?
What if I want to just reload an edit form part of my page and not all of it?
I have 5 years' experience in php but I'm new at JS and Vue, so sorry if my question is so noob.
Thank you all.
@suddy it can do 99% of what I need. If you are afraid of getting too much data, you can most likely get around it with the only prop. https://inertiajs.com/partial-reloads
But you can show your code and I might be better able to understand the problem
Please or to participate in this conversation.