4
votes

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 &rarr;</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.

2
Is your homa.blade.php the view you get from a subfolder, and not root yourwebsite.com/? - Unnawut
to youwebsite.com is rooting but to youwebsite.com/posts/topic-name-here got error - Mik
So the url you got from <a href="..."> is correct, but going to that url causes the problem right? Or is it wrong from the url produced? - Unnawut
problem was in route I'm used Route::get('/posts/{$slug}') with $ i should use without. :) - Mik

2 Answers

3
votes

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 &rarr;</a>

To this:

<a href="{{ URL::route('post-show', $post->slug) }}">Read more &rarr;</a>

Or use route helper function:

<a href="{{ route('post-show', $post->slug) }}">Read more &rarr;</a>
1
votes

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)