Support the ongoing development of Laravel.io →
Database Views Forms

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

Last updated 3 years ago.
0

Then, no ones reply ...

0

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

0

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>
Last updated 9 years ago.

derkatzer liked this reply

1

Sign in to participate in this thread!

Eventy

Your banner here too?

csmatyi csmatyi Joined 12 Aug 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.