0

ビューから json を取得します。

$container.parent().find('button[name=save]').click(function () {
    alert('we are trying to save');
  $.ajax({
    url: "/laranav/public/",
    data: {"data": handsontable.getData()}, //returns all cells' data
    dataType: 'json',
    type: 'POST',
    success: function (res) { console.log(res); alert(res); }
   /* error: function () {
      $console.text('Save error. POST method is not allowed on GitHub Pages. Run this example on your own server to see the success message.');
    }*/
  });

次に、Routes.php で

// here i make the view
Route::get('/', 'CustomerController@getIndex');
// here i wanna save the retrieved json
Route::post('/', 'CustomerController@postSave');

取得したjsonをコントローラーに保存したい:

public function postSave() {
    $t = Input::get('Name');
    $c = Customer::find('DKT000142');
    $c->Name = $t;
    $c->save();
}

json の取得は次のようになります。

 data[0][Name]:Afrifield Corporation
 data[0][City]:Maidstone
 data[1][Name]:Amann Informatik AG
 data[1][City]:Reinach BL
 data[2][Name]:Antarcticopy
 data[2][City]:Antwerpen
 data[3][Name]:Autohaus Mielberg KG
 data[3][City]:Hamburg 36

これによりエラーが発生します。postSave() 関数で何か間違ったことをしているからです。

POST http://127.0.0.1/laranav/public/ 500 (Internal Server Error) 
send 
x.extend.ajax
(anonymous function) 127.0.0.1/laranav/public/:77
x.event.dispatch
v.handle

テストのために、ここで値を変更しましたが、このように機能しています

public function getOne() {
    $c = Customer::find('DKT000142');
    $c->Name = 'Amann Informatik AG';
    $c->save();
}

私のテーブルクラス

 class Customer extends Eloquent {

     //The database table used by the model.
     protected $table = '7_0 - CRONUS (ai-Patches) AG$Customer';
     public $timestamps = false;
     public $primaryKey = 'No_';
     //important columns No_ | Name | City and a lot other that i don't wanna touch
  }
4

1 に答える 1