A
A
Artem2014-11-02 10:44:35
Laravel
Artem, 2014-11-02 10:44:35

How to properly pass variable to controller via routes.php in Laravel?

Here is the code that, according to the idea, should pass $id to the controller.

Route::get('categories/id/{$id}', '[email protected]');

Here is the method in the controller:
class CategoriesController extends BaseController {

  public function testListByID($id)
  {
echo $id;
  }
}

I go to:
localhost/lvtest/public/categories/id/2
Basically I should get a value of 2 here, but instead this is:
44322a3795.jpg
What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
cha-cha, 2014-11-02
@cha-cha

Route::get('categories/id/{$id}', '[email protected] postListByID ');
and in the controller...
public function testListByID ($id)

V
Vyacheslav Plisko, 2014-11-02
@AmdY

Not so - vtest/public your url should be something like
localhost:8000/categories/id/2
if without using an internal server, then specify a virtualhost.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question