更新数据库时我的更新功能不起作用

时间:2019-05-22 12:46:44

标签: php laravel

我在“公司模型”中的更新功能中包含以下代码,但是它不更新数据库吗?

public function update(Request $request, Company $company)
    { 
        $companyupdate = Company::where('id', $company->id)->update([
                                           'name'=>$request->input('name'),
                                           'description'=>$request->input('description') 
                                        ]);
        if($companyupdate){ 
            return redirect()->route('companies.show',['company'=>$company->id])
                         ->with('success','Company Updated Successfully');
        } 


        return back()->withInput();
    }

以下是我的视图代码,其中包含表单,该表单将记录发送到update函数。但是它没有更新数据库中的记录。谁知道问题出在哪里.. ??我在哪里在代码中犯了错误

@extends('layouts.app')

@section('content')
   <div class="col-md-9 col-lg-9 col-sm-9 pull-left">
   <!-- Jumbotron -->

       <div class="row col-lg-12 col-md-12 col-sm-12" style="background-color:white; margin:10px;">
           <form mehtod="post" action="{{ route('companies.update', [$company->id]) }}">
               {{ csrf_field() }}
               <input type="hidden" name="_method" value="put">

               <div class="form-group">
                   <label for="company-name">Name<span class="required">*</span></label>
                   <input placeholder="Enter Name"
                       id="company-name"
                       required
                       name="name"
                       spellcheck="false"
                       class="form-control"
                       value="{{$company->name}}"
                   />
               </div>
               <div class="form-group">
                   <label for="company-content">Description</label>
                   <textarea placeholder="Enter Description"
                       id="company-content"
                       required
                       name="description"
                       spellcheck="false"
                       class="form-control autosize-target text-left"
                       rows="5"> 
                       {{ $company->description }}</textarea>
               </div>
               <div class="form-group">
                   <input type="submit" class="btn btn-primary" value="Submit"/>
               </div>
           </form>
       </div>
   </div>

   <div class="col-sm-3 col-md-3 col-lg-3 pull-right">
        <!-- <div class="sidebar-module sidebar-module-inset">
       <h4>About</h4>
           <p>Etiam porta <em>sem malesuada magna</em> mollis euismod. Cras mattis consectetur purus sit amet fermentum. Aenean lacinia bibendum nulla sed consectetur.</p>
         </div>-->
         <div class="sidebar-module">
           <h4>Actions</h4>
           <ol class="list-unstyled">
             <li><a href="/companies/{{ $company->id }}">View Company</a></li>
             <li><a href="/companies">All Companies</a></li>
           </ol>
         </div>
         <!--<div class="sidebar-module">
           <h4>Members</h4>
           <ol class="list-unstyled">
             <li><a href="#">March 2014</a></li>
           </ol>
         </div>-->
   </div>
   @endsection

````

0 个答案:

没有答案