Tell me how to transfer the variable to the route through the route?

Route::post('/addCat', 'addOperationController@addCategory'); 

Here is the call to the controller method. You need to pass a variable to this method.

    1 answer 1

    Variables are transferred to the controller via routes with the help of parameters ( see the documentation ), which are indicated in curly brackets

     Route::get('/addCat/{cat_name}', 'addOperationController@addCategory'); 

    The addCategory method addCategory should be:

     public function addCategory($cat_name) { // при наборе адреса site.ru/addCat/test переменная $cat_name // примет значение test } 

    If you pass the value through the form POST method for the route

     Route::get('/addCat', 'addOperationController@addCategory'); 

    then your controller should look like this:

     public function addCategory(Request $request) { // Здесь поле с именем cat_name можно будет получить так: // $request->cat_name } 

    Here is a link to the related documentation.

    • I do not quite understand, to be honest. And if I need to pass through the post? Also transmit? - Andrei
    • @ Andrei, yes, just write instead of get post. - Artem Polikarpov
    • And how to determine cat_name? - Andrei
    • @ Andrew, in what sense to determine? - Artem Polikarpov
    • Well we transfer cat_name. I need to store the value of $ _POST ['categoryName'] in it. Either I misunderstood you) - Andrei