【问题标题】:Route not defined. (laravel)路线未定义。 (拉拉维尔)
【发布时间】:2019-05-26 01:36:21
【问题描述】:

我低于 错误:

ErrorException 路由 [iocallreport/export-file/] 未定义。 (看法: E:\xampp\htdocs\ec2\html\pbxreport\resources\views\cms\reports\iocallreport.blade.php)

查看代码:

 <a href="{{ route('iocallreport/export-file/',['type'=>'xls']) }}">Download Excel xls</a> |

 <a href="{{ route('iocallreport/export-file/',['type'=>'xlsx']) }}">Download Excel xlsx</a> |

 <a href="{{ route('iocallreport/export-file/',['type'=>'csv']) }}">Download CSV</a>

以下是我在 web.php

中的 route
Route::get('/iocallreport/export-file/{type}', 'Cms\ReportsController@exportFile');

【问题讨论】:

标签: php laravel


【解决方案1】:

这样做

<a href="{{ url('iocallreport/export-file/',['type'=>'xls']) }}">Download Excel xls</a> |

<a href="{{ url('iocallreport/export-file/',['type'=>'xlsx']) }}">Download Excel   xlsx</a> |

<a href="{{ url('iocallreport/export-file/',['type'=>'csv']) }}">Download CSV</a>

我猜route() 助手只适用于named routes。所以你的代码找不到名称为iocallreport/export-file的路由

如果你想使用route() 助手,那么试试这个。

Route::get('/iocallreport/export-file/{type}', 'Cms\ReportsController@exportFile')->name('iocallreport');

在这里使用

<a href="{{ route('iocallreport',['type'=>'xls'])   }}">Download Excel xls</a> |

<a href="{{ route('iocallreport',['type'=>'xlsx']) }}">Download Excel xlsx</a> |

<a href="{{ route('iocallreport',['type'=>'csv']) }}">Download CSV</a>

您可以为您的路线指定任何合适的名称。

【讨论】:

    【解决方案2】:

    route 函数将 路由名称 作为第一个参数。所以,你必须命名你的路线:

    Route::get('/iocallreport/export-file/{type}', 'Cms\ReportsController@exportFile')->name('export_file_route');
    

    然后在route中使用这个名字:

    <a href="{{ route('export_file_route', ['type'=>'xls']) }}">Download Excel xls</a>
    

    【讨论】:

      【解决方案3】:

      请为路由添加名称并使用此名称修改辅助路由():

      Route::get('/iocallreport/export-file/{type}', 'Cms\ReportsController@exportFile')->name('export');
      
      <a href="{{ route('export', ['type'=>'xls']) }}">Download Excel xls</a> 
      

      【讨论】:

        【解决方案4】:

        您必须为路线命名:

        Route::get(
            '/iocallreport/export-file/{type}',
            'Cms\ReportsController@exportFile'
        )->name('export-file');
        

        之后,在刀片中使用路由名称:

        <a href="{{ route('export-file', ['type'=>'xls']) }}">Download Excel xls</a>
        

        见:https://laravel.com/docs/5.7/helpers#method-route

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-10-14
          • 2014-10-24
          • 2021-08-14
          • 2017-03-16
          • 2018-09-18
          • 2021-12-30
          • 2016-07-30
          • 2021-08-31
          相关资源
          最近更新 更多