data-page attribute in react #545
Unanswered
obaid
asked this question in
Help (React)
Replies: 2 comments 2 replies
-
Any ideas? |
Beta Was this translation helpful? Give feedback.
0 replies
-
So, the way Inertia is designed to work is that you only send the data you want exposed to the client-side (React) from the server. Meaning, if you don't want it client-side, don't send it from your controllers. You can see an example of this in the Ping CRM demo app, in the UsersController: class UsersController extends Controller
{
public function index()
{
return Inertia::render('Users/Index', [
'filters' => Request::all('search', 'role', 'trashed'),
'users' => Auth::user()->account->users()
->orderByName()
->filter(Request::only('search', 'role', 'trashed'))
->get()
->transform(function ($user) {
return [
'id' => $user->id,
'name' => $user->name,
'email' => $user->email,
'owner' => $user->owner,
'photo' => $user->photoUrl(['w' => 40, 'h' => 40, 'fit' => 'crop']),
'deleted_at' => $user->deleted_at,
];
}),
]);
} Notice how we transform the data prior to sending it to the client. You can find another example in the OrganizationsController, this time interacting with the pagination object: class OrganizationsController extends Controller
{
public function index()
{
return Inertia::render('Organizations/Index', [
'filters' => Request::all('search', 'trashed'),
'organizations' => Auth::user()->account->organizations()
->orderBy('name')
->filter(Request::only('search', 'trashed'))
->paginate()
->withQueryString()
->through(function ($organization) {
return [
'id' => $organization->id,
'name' => $organization->name,
'phone' => $organization->phone,
'city' => $organization->city,
'deleted_at' => $organization->deleted_at,
];
}),
]);
} Hope that helps! |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Is there a way to not expose everything in
data-page
attribute in inertia-react?Beta Was this translation helpful? Give feedback.
All reactions