Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jakegroves's avatar

Using multiple arguments in form route + NotFoundHttpException

I am using Laravel 5.2, basically what i'm trying to do is use a 'DELETE' form, that posts the $lesson->id and $student->id I am getting an error though:

ErrorException in LessonStudentsController.php line 19: Missing argument 2 for App\Http\Controllers\Admin\LessonStudentsController::destroy() However if you look at my edit.blade.php code i've passed two variables? Am i doing something wrong in my routes.php?

edit.blade.php

                        <table class="table table-hover">
                            <thead>
                                <tr>
                                    <th>Students</th>
                                    <th></th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach($students as $student)
                                <tr>
                                    <td>{{ $student->name }}</td>
                                    <td>{!! Form::open([
                                        'method' => 'DELETE',
                                        'route' => ['admin.lessonstudents.destroy', $student->id, $lesson->id]
                                    ]) !!}
                                        {!! Form::submit('Delete', ['class' => 'btn btn-danger']) !!}
                                    {!! Form::close() !!}
                                      <!-- <i class="glyphicon glyphicon-trash fa-1x" data-toggle="tooltip" title="Delete" style="color:#b94a48;"></i> -->
                                    </td>
                                </tr>
                                @endforeach
                            </tbody>
                        </table>
                        <button type="submit" class="btn btn-primary btn-block">Add More Students</button>
                    </div>

routes.php

Route::group(['middleware' => ['web']], function () {
    Route::auth();
    Route::get('/', function () {
        return view('welcome');
    });
    Route::get('/home', 'HomeController@index');
    Route::get('/settings', 'SettingsController@settings');
    Route::post('/settings', 'SettingsController@storeSettings');
    Route::resource('/admin/manage', 'Admin\AdminManageUserController');
    Route::resource('/admin/module', 'Admin\ModuleController');
    Route::resource('/admin/room', 'Admin\RoomController');
    Route::resource('/admin/lesson', 'Admin\LessonController');
    Route::resource('/admin/lessonstudents', 'Admin\LessonStudentsController@destroy'); 
    Route::resource('admin/student', 'Admin\StudentController');

LessonStudentsController

<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Lesson;
use App\LessonStudent;
use App\User;
use App\Room;
use auth;
use DB;
use Validator;

class LessonStudentsController extends Controller
{
    public function destroy($id, $lesson_id)
    {
        // $lessonstudents = LessonStudent::find($id);
        // $LessonStudents->delete();

        $user = User::findOrFail($id);
        $user->lessons()->detach($lesson_id);

        // $lesson = Lesson::findOrFail($id);
        // $students = $lesson->students;

        return redirect('admin/lesson')->with('status', 'Succesfully delete user from lesson!');
    }
}
0 likes
1 reply
jakegroves's avatar

Changed some:

edit.blade.php

@foreach($students">                                <tr>
                                    <td>{{ $student->name }}</td>
                                    <td>{!! Form::open([
                                      'method' => 'DELETE',
                                      'route' => ['destroy', $student->id, $lesson->id]
                                    ]) !!}
                                        {!! Form::submit('Delete', ['class' => 'btn btn-danger']) !!}
                                    {!! Form::close() !!}
                                      <!-- <i class="glyphicon glyphicon-trash fa-1x" data-toggle="tooltip" title="Delete" style="color:#b94a48;"></i> -->
                                    </td>
                                </tr>
                                @endforeach 

routes.php

    Route::delete('/admin/lessonstudents/{$user_id}/{$lesson_id}', [
    'as' => 'destroy',
    'uses' => 'Admin\LessonStudentsController@destroy'
    ]);

LessonStudentsController

public function destroy($user_id, $lesson_id)
    {
        // $lessonstudents = LessonStudent::find($id);
        // $LessonStudents->delete();

        $user = User::findOrFail($user_id);
        dd($user);
        $user->lessons()->detach($lesson_id);

        // $lesson = Lesson::findOrFail($id);
        // $students = $lesson->students;

        return redirect('admin/lesson')->with('status', 'Succesfully delete user from lesson!');

So i fixed the second parameter issue because i was using it as a resource by accident. But now i'm getting this error:

NotFoundHttpException in RouteCollection.php line 161:

Not sure why?

I've done php artisan route:list and posted the relevant route result below:

| | GET|HEAD | admin/lessonstudents/{$user_id}/{$lesson_id} | destroy | App\Http\Controllers\Admin\LessonStudentsController@destroy | >web |

Please or to participate in this conversation.