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

s4r4ph43l's avatar

Cannot assign null to property

im learning livewire form

until chrome said Cannot assign null to property App\Livewire\EditProfile::$user of type App\Models\User

the intelephense keep showing and underline the user() and saying undefined method 'user' on $this-> user = auth()->user();

already tried this https://stackoverflow.com/questions/65042816/undefined-functions-methods-intelephense1013-laravel-homestead-vscode

still stuck the browser keep saying

Cannot assign null to property App\Livewire\EditProfile::$user of type App\Models\User

the component EditProfile

<?php

namespace App\Livewire;

use App\Models\User;
use Livewire\Component;

class EditProfile extends Component
{
    public User $user;
    public $username = '';
    public $bio = '';

    public function mount()
    {

        $this-> user = auth()->user();

        $this->username = $this->user->username;
        $this->bio = $this->user->bio;
    }

    public function render()
    {
        return view('livewire.edit-profile');
    }
}
​
0 likes
2 replies
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Sounds like you arent signed in

Add the auth middleware to the route you are visiting (in web.php)

->middleware('auth')
1 like
s4r4ph43l's avatar

@Sinnbeck thanks it clear my mind, LOL im to concentrate with the intelephense error

starting laravel from scrath without any auth

thanks for helping

Please or to participate in this conversation.