Reputation: 35
I am getting below error :
ErrorException Route [iocallreport/export-file/] not defined. (View: E:\xampp\htdocs\ec2\html\pbxreport\resources\views\cms\reports\iocallreport.blade.php)
code in view :
<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>
and below is my route in web.php
Route::get('/iocallreport/export-file/{type}', 'Cms\ReportsController@exportFile');
Upvotes: 1
Views: 4239
Reputation: 2292
Do this
<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>
I guess route()
helper only works for named routes
. So your code can not find route with name iocallreport/export-file
OR
If you want to use route()
helper then try this.
Route::get('/iocallreport/export-file/{type}', 'Cms\ReportsController@exportFile')->name('iocallreport');
and use it here
<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>
You can give any suitable name to your route.
Upvotes: 1
Reputation: 1942
You must give a name for route:
Route::get(
'/iocallreport/export-file/{type}',
'Cms\ReportsController@exportFile'
)->name('export-file');
After, use route name in blade:
<a href="{{ route('export-file', ['type'=>'xls']) }}">Download Excel xls</a>
See: https://laravel.com/docs/5.7/helpers#method-route
Upvotes: 0
Reputation: 1212
Please add name for route and modify helper route() with this name:
Route::get('/iocallreport/export-file/{type}', 'Cms\ReportsController@exportFile')->name('export');
<a href="{{ route('export', ['type'=>'xls']) }}">Download Excel xls</a>
Upvotes: 0
Reputation: 54841
route
function takes route name as first argument. So, you have to name your route:
Route::get('/iocallreport/export-file/{type}', 'Cms\ReportsController@exportFile')->name('export_file_route');
And then use this name in route
:
<a href="{{ route('export_file_route', ['type'=>'xls']) }}">Download Excel xls</a>
Upvotes: 2