E
E
Emil Rakhmatullin2019-02-23 15:28:19
Laravel
Emil Rakhmatullin, 2019-02-23 15:28:19

Why am I not getting a record from the database in the route?

I am not getting data into a variable $post.
Here is the route:

Route::get('catalog/{category}/{post}', function ($id) {
  $post = DB::table('posts')->find($id);
  dd($post);
  return view('view-product', compact('post'));
});

I get NULL, not a record from the database, but if I substitute the id myself, I get the desired record. What's wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Apokin, 2019-02-23
@Emchik

Maybe it needs to be?

Route::get('catalog/{id}/{id2}', function ($id,$id2) {
  dd($id,$id2);
  $post = DB::table('posts')->find($id);
  return view('view-product', compact('post'));
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question