chrmpt
1 week ago
189
10
Laravel

OnClick execute function

Posted 1 week ago by chrmpt

Hi Guys, hope you can help me.

I have a tool where i can manage Member Data. Each Member can have some Tags (I call them Labels).

Now I have a dropdown with all the available labels. If I click on one Label, I want to add this Label to the Member. I already have a function in my MemberModel to do that.

Here is my Approach:

// view.blade.php
...
<div class="dropdown-menu">
    @foreach($labels as $label)
         <a class="dropdown-item" href="" onclick="{{ ($member->attachLabel($member, $label)) }}">{{ $label->name }}</a>
    @endforeach
</div>

However, with this approach, the function gets executed for all the dropdown items - and i don't even have to click at them. Whenever I reload the page, the current member gets assigned all the available Labels.

How can I change it to only execute the Model Function when I click on the button?

thanks already for your help. I have been searching the internet already for that, couldn't find anything that helped.

Please sign in or create an account to participate in this conversation.