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

domthomas-dev's avatar

Laravel nova custom card problem

I can't get the resourceId in a custom card, at the compute function. Someone would have the trick?

class CountRelationshipsPerUser extends Card
{
    /**
     * The width of the card (1/3, 1/2, or full).
     *
     * @var string
     */
    public $width = '1/3';

    /**
     * @return CountRelationshipsPerUser
     */
    public function withCount()
    {
        $current_user = ????; ///// HERE
        return $this->withMeta([
            'my_count' => MyModel::where('user_id', $current_user)->count(),
        ]);
    }

    /**
     * Get the component name for the element.
     *
     * @return string
     */
    public function component()
    {
        return 'count-relationships-per-user';
    }
}
0 likes
6 replies
aurawindsurfing's avatar

We do use nova ;-)

Try that:

public function withCount()
    {
        $current_user = $this->user_id;
         ...
    }

$this will relate to the actual Nova Resource it is used in. So if we are talking about the user then it should work.

Hope it helps!

domthomas-dev's avatar

No, the error message is :

Undefined property: Client\CountRelationshipsPerUser\CountRelationshipsPerUser::$user_id

And I don't want the connected user, only the current resource.

Please or to participate in this conversation.