Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Emokores's avatar

Cannot access usePage() variable in Welcome.jsx page - Inertia with ReactJS

I have a Welcome.jsx page that I want to display company_name from the Setting model. But when I pass the variable and I console.log(setting), it returns a null.


const {setting} = usePage().props

console.log(setting);

This is in my web.php:


Route::get('/', function () {
    return inertia('Welcome', [
        'setting' => Setting::get()->first(),
    ]);
});

I can't get why the data is not being displayed.

0 likes
5 replies
Sinnbeck's avatar

Start by passing a static value. If that does not work, show the component

Route::get('/', function () {
    return inertia('Welcome', [
        'setting' => 'please work',
    ]);
});
 
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Also this can be simplified

Setting::query()->first() 
Emokores's avatar

@Sinnbeck Thanks for the database tip. When I pass the static value, it works perfectly. However, the dynamic value still fails.

Emokores's avatar

@Sinnbeck There is data in the settings table. But, I figured out where the problem was. My settings table has a team_id field. The Setting model had a trait FilterByTeam which filters by current_team of the authenticated user, and on the Welcome page there was no authenticated user. So it was returning null. When I removed the trait, it worked.

Please or to participate in this conversation.