Get single data request with id or slug on Inertiajs and react code

Viewed 23

I am beginner in writing program using Inertiajs, i have been working using both laravel and react js both separately. but in case of Inertia using to combine the two i got stuck in getting a single data from the controller and also to send bunch to the controller from the view

1 Answers

it's hard to understand what's your problem exactly. but as I understand your problem is transferring data between server-side and client-side nodes of your app.

to transfer data from controller to client-side(react component) :

use Inertia\Inertia;

class UsersController extends Controller
{
    public function show(User $user)
    {
        return Inertia::render('Users/Show', [
            'user' =>$user,
        ]);


    }
}

and you can get data(user object) in your component's props.

//...

export function Show = ({user})=>{

// access to the user object

}

//...

to transfer data from client-side to server-side use :

import { Inertia } from '@inertiajs/inertia'

Inertia.get(url, data, options)
Inertia.post(url, data, options)
Inertia.put(url, data, options)
Inertia.patch(url, data, options)
Inertia.delete(url, options)
Inertia.reload(options)

for more information see Manual visits

Related