首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在表单上提交时更新表中的新列

如何在表单上提交时更新表中的新列
EN

Stack Overflow用户
提问于 2019-09-18 14:01:30
回答 1查看 73关注 0票数 0

所以,我有一个从表单收集日期到数据库的报告系统。我只想更新,在新闻表格中,列活动,输入隐藏的name=“活动”,当我点击提交在我的表单上,我不知道怎么做,我现在只是保存在报告中的输入,但我也想更新列活动从新闻。

路由

Route::post('career_report', 'CareerSolutionController@careerReport');

这里是我的控制器

代码语言:javascript
复制
public function careerReport(requ $request, $id)
    {

        $report = \App\Reports::create([
                        'user_id' => $request['user_id'],
                        'username' => $request['username'],
                        'user_id_posted' => $request['user_id_posted'],
                        'username_posted' => $request['username_posted'],
                        'career_solution_id' =>$request['career_solution_id'],
                        'subject' =>$request['subject'],
                        'why_reporting' =>$request['why_reporting'],
                        'why_reporting_message' =>$request['why_reporting_message'],
                        'additional_message' =>$request['additional_message'],
                        'comment' =>$request['comment'],
                        'comment_user' =>$request['comment_user'],
                        'comment_id' =>$request['comment_id'],





                    ]);
                    $news = News::findOrfail($id);

                    $news->active = $request['active'];



                    $news->save();
                    if($news != ""){
                        flash('News has been updated successfully', 'success');
                    }else{
                        flash('News update fail', 'warning');
                    }

        if($report != ""){
            flash('Career solution report submited', 'success');
        }else{
            flash('Career solution report', 'warning');
        }


        return Redirect::back();


    }

这里是我的观点:

代码语言:javascript
复制
<form role="form" action="/career_report" method="post" id="yourFormId">
            <input type="hidden" name="_token" value="{{ csrf_token() }}">
            @if(Sentinel::check())
            <input type="hidden" name="user_id"  value="{{ Sentinel::check()->id }}">
            <input type="hidden" name="username"  value="{{ Sentinel::check()->username }}">
            @endif

            <input type="hidden" name="subject" value="{{url()->current()}}">
            <input type="hidden" name="user_id_posted" value="{{ $news->user->id }}">
            <input type="hidden" name="username_posted" value="{{ $news->user->username }}">
            <input type="hidden" name="career_solution_id" value="{{ $news->id}} ">
            <input type="hidden" name="active" value="2">
            <input type="hidden" name="comment" value="">
            <input type="hidden" name="comment_user" value=" ">
            <input type="hidden" name="comment_id" value=" ">
    <div class="tab-content">
            <div class="tab-pane active" role="tabpanel" id="step1">
                    <h3 style="text-align: center">Why are you reporting this content :</h3>

                    <ul style="list-style: none">
    <li>

    <input type="radio" id="box-9" name="why_reporting" value="Spam">
    <label for="box-9">Spam</label>

    <div class="check"></div>
    <small id="box-9-s" style="display: none">I consider this content irrelevant and annoying.</small>
    </li>

    <li>
    <input type="radio" id="box-10" name="why_reporting" value="Fake Profile">
    <label for="box-10">Fake Profile</label>

    <div class="check"><div class="inside"></div></div>
    <small id="box-10-s" style="display: none">This content was posted by way of a profile that clearly doesn't represent a real person.
    </small>
    </li>

    <li>
    <input type="radio" id="box-11" name="why_reporting" value="Advertising">
    <label for="box-11">Advertising</label>

    <div class="check"><div class="inside"></div></div>
    <small id="box-11-s" style="display: none">This content is or contains advertising.
    </small>
    </li>
    <li>
    <input type="radio" id="box-12" name="why_reporting" value="Untrustworthy source">
    <label for="box-12">Untrustworthy source</label>

    <div class="check"><div class="inside"></div></div>
    <small id="box-12-s" style="display: none">This content is from an untrustworthy source and contains unverifiable statements.
    </small>
    </li>
    <li>
    <input type="radio" id="box-13" name="why_reporting" value="Defamatory">
    <label for="box-13">Defamatory</label>

    <div class="check"><div class="inside"></div></div>
    <small id="box-13-s" style="display: none">The reported content is insulting or defamatory to me or other people.
    </small>
    </li>
    <li>
    <input type="radio" id="box-14" name="why_reporting" value="Violence or pornography">
    <label for="box-14">Violence or pornography</label>

    <div class="check"><div class="inside"></div></div>
    <small id="box-14-s" style="display: none">This content contains violence or pornography.
    </small>
    </li>
    <li>
    <input type="radio" id="box-15" name="why_reporting" value="Violates IP rights">
    <label for="box-15">Violates IP rights</label>

    <div class="check"><div class="inside"></div></div>
    <small id="box-15-s" style="display: none">This content includes third-party content (e.g. an image) posted under their own name.
    </small>
    </li>
    <li>
    <input type="radio" id="box-16" name="why_reporting" value="Promotes structural distribution measures">
    <label for="box-16">Promotes structural distribution measures</label>

    <div class="check"><div class="inside"></div></div>
    <small id="box-16-s" style="display: none">This content promotes a chain distribution system, multilevel selling or pyramid sales.
    </small>
    </li>
    <li >
    <input type="radio" id="box-17" name="why_reporting" value="Other">
    <label for="box-17" id="other">Other</label>

    <div class="check"><div class="inside"></div></div>
    <div class="form-group" id="mydiv" style="display: none">
    <textarea class="form-control" id="exampleFormControlTextarea1" rows="3" placeholder="Please let us know why you're reporting this content:
    " style="resize: none" name="why_reporting_message"></textarea>
    </div>
    </li>
    </ul>


                    <ul class="list-inline pull-right">
                        <li><button type="button" class="btn btn-default" data-dismiss="modal">Close</button></li>
                            <li><button style="background-color: #18ba9b;border-color: white" type="button" class="btn btn-primary next-step">Save and continue</button></li>
                    </ul>
            </div>
            <div class="tab-pane" role="tabpanel" id="step2">
                    <h3>Why would you like to report this?</h3>
                    <div class="form-group">
    <textarea class="form-control" id="exampleFormControlTextarea1" rows="5" style="resize: none" placeholder="
    Please let us know why you're reporting this content:" name="additional_message"></textarea>
    </div>
                    <ul class="list-inline pull-right">
                        <li><button type="button" class="btn btn-default" data-dismiss="modal">Close</button></li>
                            <li><button type="button" class="btn btn-default prev-step">Previous</button></li>
                            <li><button style="background-color: #18ba9b;border-color: white" type="submit" class="btn btn-primary btn-info-full next-step" id="save">Submit your report</button></li>
                    </ul>

            </div>
            <div class="tab-pane" role="tabpanel" id="step3">
                    <h2 class="title-box-v2" style="font-size: 17px !important;line-height: 35px">We'll look into this as soon as possible. Thanks for helping us improve the quality of content on Workstickers.</h2>
                    <p style="text-align: center">You have successfully completed all steps.Flagged content and users are reviewed by Workstickers staff 24 hours a day, seven days a week to determine whether they violate Community Guidelines. Accounts are penalized for Community Guidelines violations, and serious or repeated violations can lead to account termination.
    </p>
<div style="text-align: center;margin-top: 50px;color: #555">Manage your reports -  <a href="{{ url('my-reports') }} " style="text-decoration: underline;color: #18ba9b;font-weight: 700">View all my reports</a></div>
<ul class="list-inline pull-right">
<li><button type="button" class="btn btn-default" data-dismiss="modal">Close</button></li>
</ul>
            </div>

            <div class="clearfix"></div>
    </div>
    </form>

现在,我需要将active输入与type="hidden"一起保存在News表中,列为active,在我的表单上提交。如何使用新输入更新active列,仅在从报表提交时更新?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-09-18 19:18:45

以下是几个选择:

如果您想从以下位置获取$id:

代码语言:javascript
复制
public function careerReport(requ $request, $id)

你的路线应该是这样的:

代码语言:javascript
复制
Route::post('career_report/{id}', 'CareerSolutionController@careerReport');

并将id添加到路由中:

代码语言:javascript
复制
<form role="form" action="/career_report/{{ $news->id }}" method="post" id="yourFormId">

或者您可以使用表单上的ID,从函数中删除$id

代码语言:javascript
复制
public function careerReport(requ $request)

然后这样做:

代码语言:javascript
复制
$id = $request['career_solution_id']; // looks like this is the ID you ar looking for

$news = News::findOrfail($id);
$news->active = $request['active'];
$news->save();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57994580

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档