0
我正在使用vue和laravel。我試圖保存數組對象,但無法做到這一點,雖然我可以保存單個對象。這裏是我的代碼 App.vue如何將對象數組保存到laravel中的mysql數據庫?
// Not working
saveData(){
this.axios.post('/addperson', **this.rows**).then((response) => {
console.log("WOW");
})
}
//working
saveData(){
this.axios.post('/addperson', **this.rows[0]**).then((response) => {
console.log("WOW");
})
}
這裏是我得到的錯誤,當我通過陣列控制器代碼。
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\OrderPerson;
class PersonController extends Controller
{
public function create(Request $request){
$person = new Person([
'name' => $request->get('name'),
'age' => $request->get('age'),
'user_id' =>$request->get('user_id')''
]);
$person->save();
return response()->json('Successfully added');
}
}
任何機構可以幫助我保存陣列嗎?
你可以用serialise的方法來存儲db @ – iCoders
@iCoders,你可以給我參考鏈接嗎? – Hitendra
https://stackoverflow.com/questions/8641889/how-to-use-php-serialize-and-unserialize – iCoders