Php 如何使用laravel雄辩查询在数据库中存储html内容
我想将Php 如何使用laravel雄辩查询在数据库中存储html内容,php,laravel,Php,Laravel,我想将html表存储到我的数据库中,但它抛出了这个错误 数组到字符串的转换 我正在将html表从javascript发布到我的phpcontroller var html = '<table><thead><tr><th>Product Name</th><th>Price</th></tr></thead><tbody><tr><td>Alphabet
html
表存储到我的数据库中
,但它抛出了这个错误
数组到字符串的转换
我正在将html表从javascript
发布到我的php
controller
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)
}
});
addslashes
函数只接受字符串,您必须使用类才能获取提交的数据:
use Illuminate\Http\Request;
...
Route::post('store',function(Request $request) {
$toStore = ['table' => addslashes($request->input('table'))];
\App\product_table::create($toStore);
});
之所以出现此错误,是因为需要字符串,然后将数组传递给函数 您只需将请求数组传递给
create()
方法:
\App\product_table::create(request()->all());
如果仍要使用addslashes()
,请执行以下操作:
\App\product_table::create(['table' => addslashes(request('table'))]);
您从我的答案中复制粘贴了
['table'=>addslashes(…)]
,但您忘记了从末尾删除额外的)
。
\App\product_table::create(['table' => addslashes(request('table'))]);