4

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.

4
  • Is your homa.blade.php the view you get from a subfolder, and not root yourwebsite.com/? Commented Jun 23, 2014 at 12:01
  • to youwebsite.com is rooting but to youwebsite.com/posts/topic-name-here got error Commented Jun 23, 2014 at 12:04
  • 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? Commented Jun 23, 2014 at 12:09
  • problem was in route I'm used Route::get('/posts/{$slug}') with $ i should use without. :) Commented Jun 23, 2014 at 12:53

2 Answers 2

3

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>
Sign up to request clarification or add additional context in comments.

Comments

1

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)

4 Comments

I agree. In addition to that, I'm not sure but this Route::get('/posts/{$slug}'...) might also be causing a problem, does it work with the $ sign?
still not working, in previous project for me worked with URL::action() too.
Uhm, I never checked that, but I guess it's treated as a string
holly crap, from where i dreamed that Route::get('/posts/{$slug}') need to use with $... thanks that was a problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.