How to pass variables from a view to a controller without using forms in Laravel?

I use a RESTful controller and pass variables (using forms), it works great here.

Now for some reason I need to use a simple link created using action()and a dedicated route for the action @create.

In my view, several similar links are created with different parameters:

<a href="{!! action('\App\Http\Controllers\Admin\Franch\Category\SubCategoryController@create', array('mainCategoryName' => $mainCategoryName)) !!}">

This works because I see this in the url:

/create?mainCategoryName=some_sample_name

But the route does not pass the variables to the @create action OR the controller does not receive it for somereason:

Route::get('admin/franch/sub_categories/create', ['uses' => 'Admin\Franch\Category\SubCategoryController@create');

I wonder how to transfer variables from views to specific controllers using the GET and POST methods.

And this is my @create controller:

public function create($mainCategoryName = false)
{
        dd($mainCategoryName);
....

It always gives false.

+4
1

Ajax

$.ajax({
  type: "POST",//Or Get
  url: url,
  data: {"var_name":variable},
  success: success,
  dataType: dataType
});

. :

Input::get('var_name');
+2

Source: https://habr.com/ru/post/1629546/


All Articles