Hello everybody. I would like to create an administration page for my users on my website. For this I have made a table which displays the id, name, etc for the users in my users table. What I want is a separate column with a Delete button or delete link, which when I press it, it deletes that user from the table. This is the code I've come up with in the view page where I code the table:
@foreach($users as $u)
<tr>
<td>{{ $u->id }}</td>
<td>{{ $u->grp }}</td>
<td>{{ $u->level }}</td>
<td>
<a href="{{ URL::route('adminview') }}">Edit</a>
</td>
<td>
{{ Form::open(array('action'=>array('AdminController@destroy',$u->id))) }}
{{ Form::submit('Delete') }}
{{ Form::close() }}
</td>
</tr>
@endforeach
What do I need to write in routes.php? What do I need to write in the controller?
Thanks!
csmatyi
View
{!! Form::open(['url' => ['employee/del', $record['user_id_fk']], 'method' => 'delete']) !!} <a href="/employee/del/{!!$record['id']!!}" onclick='return confirm("Are you sure you want to delete ?")'></a> {!! Form::close() !!}
Route
Route::get('employee/del/{id}', 'EmployeeController@destroy');
Controller
public function destroy($id){ //delete query & functinality }
It may works for you
I usually make a route for that, it's maybe not obeying the restful principles, but it works and I haven't found better solutions yet.
Your route look something like
Route::resource('employee', 'EmployeeController');
Then add this route too
Route::get('employee/delete/{employee}', ['as' => 'employee.delete', 'uses' => 'EmployeeController@destroy']);
You can now define your link as
<a href="{{ route('employee.delete', $employee->id) }}">Delete</a>
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community