Reputation: 659
I have a little problem with passing some data from my view to my controller.
Please have a look at this code snippet:
{!! Form::open(['action' => 'DomainController@detach', 'method' => 'post']) !!}
@foreach($domains as $domain)
<tr>
<td>{{ $domain->name }}</td>
<td>{{ $domain->tld }}</td>
<td id="hello">
@foreach($domain->tags as $tag)
{{ $tag->name }},<br>
@endforeach
</td>
<td>
@foreach($domain->tags as $tag)
{!! Form::hidden('tag_id[]', $tag->id) !!}
<button name="domain_id" value="{{ $domain->id }}" class="glyphicon glyphicon-trash"></button>
<br>
@endforeach
</td>
</tr>
@endforeach
{!! Form::close() !!}
In my Controller is a :
$input = Input::all();
return $input;
In my code ( in the last ) is a button. If I press teh button, I'm getting directed to my controller action. I'm returning the die data in my $input variable and it allways shows me the same tag_id. Allways the very last tag_id of this domain. I don't know why and couldn't figure it out.
Upvotes: 0
Views: 68
Reputation: 1373
It should be:
{!! Form::hidden('tag_id[]', $domain->pivot->id) !!}
you're missing the [] in input
Upvotes: 1
Reputation: 2166
You have 2 fields with the same name:
{!! Form::hidden('tag_id', $domain->pivot->id) !!}
<button name="tag_id" value="{{ $domain->id }}" class="glyphicon glyphicon-trash"></button>
Upvotes: 0