C
C
Corsair_TM2018-11-06 12:52:11
Laravel
Corsair_TM, 2018-11-06 12:52:11

How to properly validate the parameters passed in the URL?

Good afternoon. Please tell me what I'm doing wrong.
There is a route:

Route::get('/user/{name}', 'Page\[email protected]');

Created a userName method in PageController:
public function userName(Request $request, $name)
{
    $request->validate([
        'name' => 'required|alpha_num|max:50',
    ]);
}

For example, I follow the link http: // site address / user / userName
If the method returns return $ request-> name, then I will get userName, but it does not work in the validation itself, in the validation this parameter turns out to be empty.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
holfza, 2018-11-06
@Corsair_TM

https://laravel.com/docs/5.7/routing#parameters-re...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question