How to Post and insert Data into DB using Laravel, Bootstrap Modal and Ajax

Issue is i am not able to get bootstrap modal textarea input value using Input::get(), it returns null.

Modal’s submit and text input(my view):

<button type="button" class="btn btn-danger" onclick="customModalSubmitFunction('modalID')">Submit</button>

JS function:

function customModalSubmitFunction(modalID){
    $.ajax({
        type: "POST",
        url: "urlRouteToController"
    });
}

Route.php route

Route::post('urlRouteToController', array(
    'uses' => 'myController@insertValueIntoDatabase',
    'as' => 'urlRouteToController'
));

Controller

public function myController(){
   $dbModel = new Model;
   $dbModel->column1 = Input::get('textbox1');
   $dbModel->save();
}

In conclusion, i cannot get posted data using Input::get(‘textbox1’). But inserting data into database as null values (because i cannot get textbox value) part works.

Thanks in advance.


Source: laravel

Leave a Reply