Reputation: 151
I have read other questions in this forum to fix this problem, but nothing helped me.
I'm receiving this error only in one folder in other folder laravel works perfect no errors. Error is:
Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException
The code i using. 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>
routes.php
Route::get('/posts/{$slug}', array(
'as' => 'post-show',
'uses' => 'PostController@getShow'
));
and controller is PostController.php
<?php
class PostController extends BaseController {
public function getShow($slug) {
echo 'Tets';
}
}
This is all my code nothing more.
Upvotes: 4
Views: 22348
Reputation: 146191
Actually you should use (Remove $
from {$slug}
):
Route::get('/posts/{slug}', array(
'as' => 'post-show',
'uses' => 'PostController@getShow'
));
Also change:
<a href="{{ URL::action('post-show', $post->slug) }}">Read more →</a>
To this:
<a href="{{ URL::route('post-show', $post->slug) }}">Read more →</a>
Or use route
helper function:
<a href="{{ route('post-show', $post->slug) }}">Read more →</a>
Upvotes: 3
Reputation: 25425
URL::action
(as the name implies) expects an action, not a route name as you're passing.
public string action(string $action, mixed $parameters = array(), bool $absolute = true)
You should use route():
URL::route('post-show', array($post->slug))
public string route(string $name, mixed $parameters = array(), bool $absolute = true, Route $route = null)
Upvotes: 1