Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mattysmart's avatar

How to retrieve ajax data in controller

Hello all.

I have an ajax request as seen below:

    $.ajaxSetup({
        headers: { 'X-CSRF-Token' : $('meta[name=_token]').attr('content') }
    });
    jQuery.ajax({
        url:'/group/create',
        type: 'GET',
        data: {
            name: groupName,
            colour: "red"
        },
        success: function( data ){

            console.log(data);
        },
        error: function (xhr, b, c) {
            console.log("xhr=" + xhr + " b=" + b + " c=" + c);
        }
    });

This is my route:

Route::get('/group/create', ['middleware' => 'auth', 'uses' => 'GroupController@create']);

This is my controller:

public function create()
{
    $name = $_GET['name'];
    $colour = $_GET['colour'];
   $input = [$name,$colour];

    return array('input' => $input);
}

How would i do this in a laravel way in my controller?

0 likes
1 reply

Please or to participate in this conversation.