1

I wrote this code in file RouteServiceProvider.php that is located in app/Providers directory.

In method boot:

$this->pattern('{id}', '[0-9]+');

then according to what I read, I thought if I write this code:

Route::get('/user/{id}', function ($id){
    return $id;
});

in file web.php in routes directory the id parameter accept just int value, but when i test this url: http://127.0.0.1:8000/user/a I saw a is returned.

Where is the problem and how can I make pattern?

1 Answer 1

2

According to the docs you should use Route:: facade instead of $this-> and id instead of {id}:

public function boot()
{
    Route::pattern('id', '[0-9]+');

    parent::boot();
}
Sign up to request clarification or add additional context in comments.

Comments

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.