Shaik
Shaik

Reputation: 296

Redirecting to a laravel route link on button click

On button click. I want page to redirect to a laravel route url using a separate script.

Below is my code:

<button id="myButton">Home</button>

<script type="text/javascript">
document.getElementById("myButton").onclick = function () {
    location.href = "{{ route('customer.wishlist.remove',$item->id) }}";
};

onclick it directly showing the route link in the browser tab.

Please help me where iam going wrong. thank you.

Upvotes: 1

Views: 3190

Answers (2)

VIKAS KATARIYA
VIKAS KATARIYA

Reputation: 6005

pass CSRF token and write window.location.href in your code

    <button id="myButton">Home</button>
    <script type="text/javascript">
    document.getElementById("myButton").onclick = function () {
        window.location.href = "{{ route('customer.wishlist.remove',$item->id) }}";
    };

or

<a href="{{ url('/path/' . $item->id . '/path(edit like)') }}" class="btn btn-xs btn-info pull-right">BUttonn naame</a>

Upvotes: 1

alprnkeskekoglu
alprnkeskekoglu

Reputation: 318

Try this

<button id="myButton">Home</button>

<script type="text/javascript">
document.getElementById("myButton").onclick = function () {
    window.location.href = "{{ route('customer.wishlist.remove',$item->id) }}";
};

Upvotes: 1

Related Questions