【问题标题】:Route [clients.projects] not defined路线 [clients.projects] 未定义
【发布时间】:2020-09-13 15:03:26
【问题描述】:

我使用 Laravel 开始了一个新项目,并收到此错误消息

Route::get('projects/{id}', ['uses' => 'ManageClientsController@showProjects'])->name('clients.projects');

当我这样做时

<a href="{{ route('clients.projects') }}">{{ $client->name }}</a></td>

的作用是什么。在客户和项目之间,我应该如何称呼这条路线

这是我的路线文件:

Route::group(
        ['prefix' => 'clients'], function() {
        Route::post('save-consent-purpose-data/{client}', ['uses' => 'ManageClientsController@saveConsentLeadData'])->name('clients.save-consent-purpose-data');
        Route::get('consent-purpose-data/{client}', ['uses' => 'ManageClientsController@consentPurposeData'])->name('clients.consent-purpose-data');
        Route::get('gdpr/{id}', ['uses' => 'ManageClientsController@gdpr'])->name('clients.gdpr');
        Route::get('projects/{id?}', ['uses' => 'ManageClientsController@showProjects'])->name('clients.projects');
        Route::get('invoices/{id}', ['uses' => 'ManageClientsController@showInvoices'])->name('clients.invoices');

        Route::get('contacts/data/{id}', ['uses' => 'ClientContactController@data'])->name('contacts.data');
        Route::resource('contacts', 'ClientContactController');
    });

【问题讨论】:

  • 通过在 Route::get('projects/{id?}' 后面附加一个问号 Route::get('projects/{id}' 来使您的 id 参数可选。
  • 可能是你的路由uriprojects/{id}是重复的,请确保它没有在其他路由中使用

标签: php laravel


【解决方案1】:

为将来可能遇到此问题的人编辑了答案。

  1. 确保 uri 是唯一的
  2. 没有包裹你的路由的父命名空间,如果这样做,请添加带有.的父命名空间
  3. 定义路由 uri 时需要一个参数,其中包含 /{param} 而不是 /{param?}
  4. 您可以随时使用以下命令检查您的路线php artisan route:list

如果有人遇到过,希望这可以解决问题。


您需要将id 参数传递给您的路由,或者您可以尝试

替换

Route::get('projects/{id}', ['uses' => 'ManageClientsController@showProjects'])->name('clients.projects');

Route::get('projects/{id?}', 'ManageClientsController@showProjects')->name('clients.projects');

【讨论】:

  • 我仍然遇到同样的错误:Route [clients.projects] 未定义。 (查看:C:\xampp\htdocs\cms\resources\views\admin\clients_index.blade.php)我应该改变我的href吗?
  • 你有没有包裹这条路线的路线名称前缀?
  • @KayLun 请仔细检查,我已经更新了我的问题,(路线文件)
【解决方案2】:

我找到了答案,我必须这样做,因为我有一个父命名空间

{{ route('admin.clients.projects', ['id' => $client->id]) }}

谢谢大家

【讨论】:

    【解决方案3】:
    <a href="{{ route('clients.projects',['id'=>$client->id]) }}">{{ $client->name }}</a>
    

    【讨论】:

    • 同样的问题,请仔细检查我的问题,(更新)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-30
    • 2016-08-26
    • 2021-11-12
    • 2022-01-16
    • 2018-10-15
    • 2017-12-25
    • 2023-03-29
    相关资源
    最近更新 更多