Laravel Version: 5.4
新增Post::insert(["board" => $board,"content" => $content]);
後,便無法正常運行,有測試過前端傳回的資料正常
以下程式碼
PostController->
public function add(Request $request)
{
$board = $request->input('board');
$content = $request->input('content');
Post::insert(["board" => $board,"content" => $content]);
return response()->json(array(
'Msg' => "發送成功"
));
}
Post Model->
class Post extends Model
{
protected $table = 'posts';
}
ajax->
$("#send").submit(function() {
$("#submit").attr("disabled",true);
$("#submit").html('<i class="fa fa-refresh fa-spin"></i>傳送中...');
$.ajax({
type: "POST",
url: "{{ route('add') }}",
dataType: "json",
data: {
content: $("#content").val(),
board: $("meta[name=board]").attr('content')
},
success: function(data) {
$("#send")[0].reset();
$("#alert").html(data.Msg);
$("#submit").attr("disabled",false);
$("#submit").html('-發送-');
}
})
return false;
});