我已阅读此论坛中的其他问题来解决此问题,但没有任何帮助。
我只在其他文件夹中的一个文件夹中收到此错误 laravel 完美无误。 错误是:
Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException
我使用的代码。 homa.blade.php
<section>
<h2><a href="{{ URL::action('post-show', $post->slug) }}">{{ $post->title }}</a></h2>
{{ Markdown::parse(Str::limit($post->body, 300)) }}
<a href="{{ URL::action('post-show', $post->slug) }}">Read more →</a>
</section>
路由.php
Route::get('/posts/{$slug}', array(
'as' => 'post-show',
'uses' => 'PostController@getShow'
));
Controller 是 PostController.php
<?php
class PostController extends BaseController {
public function getShow($slug) {
echo 'Tets';
}
}
这就是我的全部代码。
最佳答案
实际上你应该使用(从 {$slug}
中删除 $
):
Route::get('/posts/{slug}', array(
'as' => 'post-show',
'uses' => 'PostController@getShow'
));
同时改变:
<a href="{{ URL::action('post-show', $post->slug) }}">Read more →</a>
对此:
<a href="{{ URL::route('post-show', $post->slug) }}">Read more →</a>
或者使用route
辅助函数:
<a href="{{ route('post-show', $post->slug) }}">Read more →</a>
关于php - Laravel 错误 Symfony\Component\HttpKernel\Exception\NotFoundHttpException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24365374/