I'm new in laravel and Javascript.
I have a route which looks like
Route::get('/problems/{problem}/edit', 'AdminController@editProblem');
and my page looks like image
HTML code for this page is
@foreach($in_contest->problems as $problem)
<div class="list-group">
<a href="#" class="list-group-item">
<i class="fa fa-file fa-lg"></i>
{{ $problem->title }}
<span class="pull-right">
<button onclick="callRoute()" class="btn btn-xs btn-info button">Edit</button>
</span>
</a>
</div>
@endforeach
I wrote javascript code for this onclick which is
<script type="text/javascript">
function callRoute() {
window.location = '{{ url('/problems/' . $problem->id . '/edit') }}';
}
</script>
now every time I'm clicking Edit button on P1, P2, or P3 its opening the edit page for P4. Same url is opening for all. I want when I click edit on P1 its redirect to edit page for $problem-id with P1. and same for the others too.
What is the solution of this problem?