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

dan3460's avatar

Property not found, on update

Completely new to LiveWire, but i like it. I have the following problem, i'm trying to make a card a default from a list of cards. The component is showing me all the card and it is updating the default card. The problem is when it tries to reload the list (after the update) is giving me the error that the card variable that i used doesnt exist; My code is very troglodyte but is the only way that i fund to work with Stripe: here is my livewire component:

 <?php

namespace App\Http\Livewire;

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

class CardList extends Component
{
    public $paymentMethods;
    public $user;
    /**
     * mount
     *
     * @return void
     */
    public function mount()
    {
        $this->paymentMethods = collect();
        $this->user = User::find(auth()->user()->id);
        foreach ($this->user->paymentMethods() as $paymentMethod) {
            $this->paymentMethods->push($paymentMethod->asStripePaymentMethod());
        }
    }

    public function render()
    {
        return view('livewire.card-list');
    }

    public function makeDefault($cardId)
    {
        $this->user->updateDefaultPaymentMethod($cardId);

        return redirect()->route('cardManagement');
    }
}

here is the livewire blade:

<div>
    @if (auth()->user()->hasPaymentMethod())
    <div>
        Active Cards
    </div>
    <table class="tbl">
        <thead class="tbl-head">
            <tr>
                <th>Type</th>
                <th>Number</th>
                <th>Actions</th>
            </tr>
        </thead>
        <tbody class="tbl-body">
            @foreach ($paymentMethods as $card)
            <tr>
                <td>
                    @switch($card->card->brand)
                    @case('visa')
                    <i class="fab fa-cc-visa bg-blue-600"></i>
                    @break
                    @case('mastercard')
                    <i class="fab fa-cc-mastercard bg-orange-400"></i>
                    @break
                    @case('amex')
                    <i class="fab fa-cc-amex bg-blue-400"></i>
                    @break
                    @default
                    <i class="far fa-credit-card"></i>
                    @endswitch
                </td>
                <td> ****-****-****-{{$card->card->last4}} </td>
                <td>
                    @if ($user->defaultPaymentMethod()->asStripePaymentMethod()->id == $card->id)
                    Default
                    @else
                    <div class="justify-between">
                        <button class="btn btn-info btn-xs" wire:click='makeDefault("{{$card->id}}")'>Make Default</button>
                        <button class="btn btn-danger btn-xs">Delete</button>
                    </div>

                    @endif
                </td>
            </tr>
            @endforeach
        </tbody>
    </table>

    <div class="ml-7">
        <ul>

        </ul>
    </div>
    @else
    <div class="justify-items-center">
        <div class="mt-4 text-center">
            There are no Cards Associated with the account
        </div>
        <div class="mt-4 text-center">
            Please enter one to start your subscription
        </div>
    </div>
    @endif
</div>

If i cancel the error and call the route, it load with no problem and showing the correct default card. I'm guessing livewire is tryin to only update the rows that changed and is loosing the original variable values. Any ideas.

here is the error:

ErrorException
Trying to get property 'card' of non-object (View: C:\Users\Daniel.SFP\Documents\Projects\procalc\resources\views\livewire\card-list.blade.php)
http://127.0.0.1:8000/cardManagement
0 likes
3 replies
tykus's avatar
tykus
Best Answer
Level 104

If you use the render method for initializing and re-rendering the Collection of paymentMethods, then it will be re-evaluated whenever the component needs to re-render.

dan3460's avatar

So, if, i understand correctly, i should put everything that is in the mount method under the render method, correct? If so, when the mount method should be used?

Thanks for the help,

tykus's avatar

I don't know if it is idiomatic Livewire, but yes that is how I understand it - the Collection needs to be re-evaluated every time the component is re-rendered, so the render method is the place to assign to it.

Please or to participate in this conversation.