I am using Laravel framework, where I have a form, which has a list of profiles displayed (using Profile Model). All these profiles are bound with a single checkbox array. There is a button at the top that when clicked, deletes the selected profiles (The action used here is ProfileController@deleteProfile). Also each profile has a button next to it, which when clicked, is supposed to go to ProfileController@editProfile action, but I am not sure where to specify this different action in the form. Is there a way to trigger a different action when Edit button is clicked?
@if(count($profiles) > 0)
{!! Form::open(['action' => ['AdminController@deleteProfile'], 'method' => 'POST']) !!}
{{ Form::submit('Delete Selected Profiles', ['class' => 'btn btn-danger']) }}
<table class="table">
<thead class="thead-dark">
<tr>
<th scope="col">#</th>
<th scope="col">Select</th>
<th scope="col">Title</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
@foreach($profiles as $profile)
<tr>
<th scope="row">{{ $profile->id }}</th>
<td>
<input type="checkbox" name="selectedProfiles[]" value="{{ $profile->id }}" />
</td>
<td>{{ $profile->title }}</td>
<td>
{{ Form::hidden('id', $profile->id) }}
{{ Form::submit('Edit', ['class' => 'btn btn-secondary']) }}
</td>
</tr>
@endforeach
</tbody>
</table>
{!! Form::close() !!}
@endif
Another approach I tried was to create a generalized action ProfileModify where I would pass an extra variable to specify the kind of action I wanted to implement, 'Edit' or 'Delete' but I can't find a way to pass the Hidden input conditionally to send "Edit" or "Delete" when we click 2 separate buttons.
Can someone suggest how to approach this issue, and if this is actually possible, and if not, a better possible alternative to tackle this situation?
ProfileController@editProfiledisplay the edit form for a profile?