Laravel Route Url - 查询字符串 - 多级

时间:2017-01-22 10:32:06

标签: php laravel laravel-5.3

我正在尝试实现如下的url结构。

  • example.com/clients/ {client_id} //已完成
  • example.com/clients/ {client_id} {project_id} //问题

错误是缺少[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',  
            ]);

        });

        });

观看视频

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

控制器

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

1 个答案:

答案 0 :(得分:1)

问题出在你看来。你必须在route()的数组中传递params。试试这个:

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