无法定义 laravel 视图的 href 元素
Can't define href element of laravel's view
我在 laravel web.php 文件中定义了两条路线。
Route::get('/art', ['uses'=>'Aboutcontroller@getArticles', 'as'=>'articles']);
Route::get('/art/{id}', ['uses'=>'Aboutcontroller@getArticle', 'as'=>'article']);
我想在我的视图文件中将它们用作我的超链接的 'href' 属性。
当我写下以下代码时:
*<a href="/art">I link </a> </br>
<a href="/art/800">II link </a> </br>*
工作正常。
但是当我想通过它不命名参数来使用路由时(如 laravel 官方网站的帮助主题中所述),它给了我错误:
<a href="<?php echo route('article', ['id' => 123]); ?>">IV link </a>
包含图像。
我有什么乱七八糟的?
我使用的是 laravel 的 8.2 版。目前是最新的。
Route::get('art', [\App\Http\Controllers\Aboutcontroller::class, 'getArticles'])->name('getArticles');
Route::get('art/{id}', [\App\Http\Controllers\Aboutcontroller::class, 'getArticles'])->name('getArticles');
或
Route::get('art', 'App\Http\Controllers\Aboutcontroller@getArticles')->name('getArticles');
Route::get('art/{id}', 'App\Http\Controllers\Aboutcontroller@getArticles')->name('getArticles');
blade 个文件
<a href="{{ route('getArticles') }}">IV link </a>
参数
<a href="{{ route('getArticles',['id' => 1]) }}">IV link </a>
我在 laravel web.php 文件中定义了两条路线。
Route::get('/art', ['uses'=>'Aboutcontroller@getArticles', 'as'=>'articles']);
Route::get('/art/{id}', ['uses'=>'Aboutcontroller@getArticle', 'as'=>'article']);
我想在我的视图文件中将它们用作我的超链接的 'href' 属性。
当我写下以下代码时:
*<a href="/art">I link </a> </br> <a href="/art/800">II link </a> </br>*
工作正常。
但是当我想通过它不命名参数来使用路由时(如 laravel 官方网站的帮助主题中所述),它给了我错误:
<a href="<?php echo route('article', ['id' => 123]); ?>">IV link </a>
包含图像。
我有什么乱七八糟的?
我使用的是 laravel 的 8.2 版。目前是最新的。
Route::get('art', [\App\Http\Controllers\Aboutcontroller::class, 'getArticles'])->name('getArticles');
Route::get('art/{id}', [\App\Http\Controllers\Aboutcontroller::class, 'getArticles'])->name('getArticles');
或
Route::get('art', 'App\Http\Controllers\Aboutcontroller@getArticles')->name('getArticles');
Route::get('art/{id}', 'App\Http\Controllers\Aboutcontroller@getArticles')->name('getArticles');
blade 个文件
<a href="{{ route('getArticles') }}">IV link </a>
参数
<a href="{{ route('getArticles',['id' => 1]) }}">IV link </a>