![](/img/trans.png)
[英]How to store and retrieve image contents from the database using Laravel
[英]how to store html contents in database using laravel eloquent query
我想将html
表存储到我的database
但是会引发此error
数组到字符串的转换
我正在将javascript
html表发布到我的php
控制器
var html = '<table><thead><tr><th>Product Name</th><th>Price</th></tr></thead><tbody><tr><td>Alphabet</td><td>200</td></tr></tbody></table>;
$.ajax({
url:'store',
type:'POST',
data:{table:html},
success:function(data){
console.log(data)
}
});
laravel :要插入的已发布数据
Route::post('store',function(){
$toStore = addslashes(['table' => $_POST['table']]);
\App\product_table::create($toStore);
});
您收到此错误的原因是, addslashes()
需要字符串,并将数组传递给该函数。
您可以将请求数组传递给create()
方法:
\App\product_table::create(request()->all());
如果仍然要使用addslashes()
,请执行以下操作:
\App\product_table::create(['table' => addslashes(request('table'))]);
addslashes
函数仅接受字符串,并且您必须使用Request类才能获取提交的数据:
use Illuminate\Http\Request;
...
Route::post('store',function(Request $request) {
$toStore = ['table' => addslashes($request->input('table'))];
\App\product_table::create($toStore);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.