ryank
ryank

Reputation: 395

Dynamic Routes not found

I am having trouble getting dynamic routes to work in Laravel 4

Routes

Route::any('/browse/{$id}', 'BrowseController@showProfile');

Controller

<?php

class BrowseController extends BaseController {

    public function showProfile($id)
    {
        return $car_id;
    }
}

When I go to http://localhost:8000/browse/10018

I receive a not found error

enter image description here

Any Idea what is wrong? Sorry I am new to Laravel

Upvotes: 1

Views: 319

Answers (2)

Jerodev
Jerodev

Reputation: 33186

You don't need a $ in the variable name in your route. Try using

Route::any('/browse/{id}', 'BrowseController@showProfile');

Also, you should add validation to only allow numbers:

Route::any('/browse/{id}', 'BrowseController@showProfile')->where('id', '\d+');

Upvotes: 1

David Duarte
David Duarte

Reputation: 41

The problem is in {$id}, try only {id}

Upvotes: 1

Related Questions