B
B
BonBon Slick2016-12-04 21:59:58
Laravel
BonBon Slick, 2016-12-04 21:59:58

Post output via Laravel 5 slug?

If you pass its post_id to $post , then everything works fine:

<a href="{{ url('/post/' . $product->post_id . '/show') }}">SEE POST</a>
...
Route::get('/post/{post}/show', '[email protected]');
...
  public function show(Post $post)
  {
    return view('post/single', compact( 'post') );
  }

If you pass it to slug :
<a href="{{ url('/post/' . $post->post_slug. '/show') }}"
...
Route::get('/post/{post}/show', '[email protected]');
...
  public function show($post_url)
  {
    $post = Post::where('post_slug', $post_url)->get();
    return view('post/single', compact( 'post') );
  }

Then it will return not an object, but already as a collection of objects

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene Wolf, 2016-12-04
@BonBonSlick

Instead of

$post = Post::where('post_slug', $post_url)->get();

this:
?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question