Ajax表单提交laravel



晚安,

我正在尝试使用ajax和laravel框架进行POST请求。我还在学习laravel、php和Ajax。我在这里遵循了一个教程和一些问题,但我对这件事仍然有点困惑。我有一个表格,我想提交的兴趣,用户可以选择复选框。每个复选框都有一个值,该值表示用户接收文章时可以遵循的兴趣。我的表由列(user_id(=兴趣和(follower_id(=(当前用户的id(组成。这样,当用户单击复选框时,它将提交一个新行,其中包含他们的id和感兴趣的id。我的问题是如何提交这些信息。起初,我想使用一个可以提交/生成多行的表单,但找不到解决方案。然后我读到我可以制作多个表单并使用Ajax提交它们。我目前遇到了问题,我得到了这个错误500(内部服务器错误(。有人能帮我解释一下哪里出了问题吗?这是我的代码。。。。。

HTML:

{!! Form::open(array('id'=> 'form1')) !!}
                                <div class = "form-group">
                                    <div class="col-md-6">
                                        {!! Form::label('title','Title:', ['class' => 'col-md-4 control-label']) !!}
                                        {!! Form::checkbox('interest_id', '1', true, ['class' => 'formclick submit']) !!}
                                    </div>
                                </div>
                                {!! Form::close() !!}
                                {!! Form::open(array('id'=> 'form2')) !!}
                                <div class = "form-group">
                                    <div class="col-md-6">
                                        {!! Form::label('title','Title:', ['class' => 'col-md-4 control-label']) !!}
                                        {!! Form::checkbox('interest_id', '2', true, ['class' => 'formclick submit']) !!}
                                    </div>
                                </div>
                        <input id = "submit_me" type="button" value="Click Me!"  />
                                {!! Form::close() !!}

JQuery:

    $(document).ready(function(){
var interest_id = $('.formclick');
$('.submit').click(function(){
    var interest = {
        user_id: interest_id.val()
    };
    $.ajax({
        type: 'POST',
        url: '/interest',
        data: interest,
        success: function() {
           alert('new interest');
        }
    });
});

InterestController:

    public function store(InterestRequest $interest)
{
    $interest = new Follower(array(
        'user_id' => $interest->get('interest_id'),
        'follower_id'  => Auth::id()
    ));
    $interest->save();
}

对InterestController 进行一些更改

'user_id' => $interest->input('user_id'), 

最新更新