Reputation: 4480
In my blade I have field called $jobs
. I am trying give every single form a unique url based on the $job->id
. So the url is jobs/$job->id. However when I click on the a tag for to submit the form all the urls show jobs/the last $job->id. In my case all the urls show job/386
. What should I so every url has a unique url? Here is my code.
@foreach($jobs as $job)
<form method="post" action="{{url('jobs/'. $job->id)}}" id="start-jobs">
{{csrf_field()}}
<a onclick="document.getElementById('start-jobs').submit()">( start )</a>
</form>
@endforeach
Upvotes: 0
Views: 113
Reputation: 41810
This is actually a JavaScript problem, not a Laravel problem.
All your forms have the same id (which isn't actually valid HTML), and which is why getElementById('start-jobs')
is getting you the last one. If you need to have an identifier for all of the forms, use class
instead of id
.
It seems like you should be able to use just a regular submit button instead of the submit link you're using.
@foreach($jobs as $job)
<form method="post" action="{{url('jobs/'. $job->id)}}" class="start-jobs">
{{csrf_field()}}
<input type="submit" value="( start )">
</form>
@endforeach
Upvotes: 1