【问题标题】:Laravel Route Url - Query String - Multi LevelLaravel 路由 URL - 查询字符串 - 多级
【发布时间】:2017-01-22 10:32:05
【问题描述】:

我正在尝试实现如下所示的 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;
}

【问题讨论】:

  • 你能把ClientsController@show_project的代码放上来
  • 更新了我的代码。@Bara'ayyash

标签: php laravel laravel-5.3


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2014-03-05
    • 2014-08-23
    • 1970-01-01
    • 1970-01-01
    • 2020-08-03
    • 1970-01-01
    • 2015-04-12
    • 2020-02-14
    • 1970-01-01
    相关资源
    最近更新 更多