0

I am new to development, apologies if question is basic

I am trying to add href page to the btn, but when the blade template parses url it's formatted and return error.

 $('#municipal_option').on('change',function(e){
        // console.log(e);  
        var municipal_id = e.target.value; 
        var BASEURL = "{!! url('admin/bank/') !!}";
        console.log(municipal_id);
        $.get( BASEURL + '/bankview?municipal_id=' + municipal_id, function(data){
            console.log(data);
            $("#bank_list tr").remove();
            $.each(data,function(index, bankObj){
                $('#bank_list').append('<tr class=""><td> ' + bankObj.bank_name + '</td> <td> ' + bankObj.bank_ac_no + ' </td>  <td> '+ bankObj.bank_ifsc_code +' </td> <td> <button class="btn btn-primary"> **<a href="{!! asset('bank/{{$bank->id}}/edit')!!}"> Edit </a>**  </td> <td> </td>    </tr>');


             });
});
});

The route:

| GET|HEAD  | bank/{bank}/edit   | bank.edit   | App\Http\Controllers\bankController@edit

How to point to the above route.

The url that's generated, http://localhost/public/bank/%3C?php%20echo%20e($bank-%3Eid);%20?%3E/edit

Adding to the above question, Instead of looping the result(table) in the code, can I use it independently in the blade template with hep of @foreach.

Thank you.

2 Answers 2

2

Use Javascript to replace the custom js value into the route

var url = "{{ route('bank.edit', ':municipal_id') }}";

url = url.replace(":municipal_id", municipal_id);

so...

 $('#municipal_option').on('change',function(e){
            // console.log(e);  
            var municipal_id = e.target.value; 
            var BASEURL = "{{ route('bank.edit', ':municipal_id') }}";
            BASEURL.replace(':municipal_id', municipal_id);
            console.log(municipal_id);
            $.get( BASEURL , function(data){
                console.log(data);
                $("#bank_list tr").remove();
                $.each(data,function(index, bankObj){
                    $('#bank_list').append('<tr class=""><td> ' + bankObj.bank_name + '</td> <td> ' + bankObj.bank_ac_no + ' </td>  <td> '+ bankObj.bank_ifsc_code +' </td> <td> <button class="btn btn-primary"> **<a href="{!! asset('bank/{{$bank->id}}/edit')!!}"> Edit </a>**  </td> <td> </td>    </tr>');


                });
            });
    });
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for looking to this. But this will break the first part where I get data from the path admin/bank. I am looking to add edit button and link it to the edit page where it can be accessed based on the id. Sorry to say that the above code dont work for me
I am new to developing, just incase if am pointing it wrong, please correct me
If you want to make a button to go to a edit page, just do <button onclick="location.href='{{route("bank,edit", $id)}}'"></button> If you generate the buttons via javascript, replace $id with the javascript value
Thanks @Juan, actually I replaced the href to <a href="bank/'+ bankObj.id +'/edit">'
1

Since I was trying to print an action route from a Javascript code, it was trying to print the php echo code directly, hence it yielded no result for the function.

<a href="/your_route/' + bankObj.id + '"> 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.