Search code examples
phplaravellaravel-5.3

Laravel Route Url - Query String - Multi Level


I am trying to achieve url structure like below.

  • example.com/clients/{client_id} //done
  • example.com/clients/{client_id}{project_id} // issues

Error is Missing required parameters for [Route: clients.show_project] [URI: clients/{client}/{project_id}].

Route::group(['prefix' => 'clients', 'as' => 'clients.'], function () {

        Route::get('/', [
            'uses' => 'ClientsController@index',
            'as' => 'index',
        ]);

        Route::get('/create', [
            'uses' => 'ClientsController@create',
            'as' => 'create',
        ]);

        Route::post('/store', [
            'uses' => 'ClientsController@store',
            'as' => 'store',
        ]);

        Route::group(['prefix' => '{client}', '__rp' => ['menu' => 'clients']], function () {

            Route::get('/', [
                'uses' => 'ClientsController@show_client',
                'as' => 'show',  
            ]);

         });

        Route::group(['prefix' => '{client}/{project_id}'], function () {

            Route::get('/', [
                'uses' => 'ClientsController@show_project',
                'as' => 'show_project',  
            ]);

        });

        });

On view

 <a href="{{ route('clients.show_project', $task->client_id, $task->project_id)}}">{{ $task->title }}</a>

Controller

public function show_project($client, $project_id)
    {
    $project_threads = Project_Threads::where('project_id', $project_id)->get();
    return $project_threads;
}

Solution

  • The problem is in your view. Your have to pass params in an array in route(). Try this:

    <a href="{{ route('clients.show_project', [$task->client_id, $task->project_id])}}">{{ $task->title }}</a>