douyuan4357 2019-05-22 12:46
浏览 42

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

I have the following code in my update function in Company Model but it does not update data base?

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();
    }

And the below is my view code that contains form, which sends record to update function.But it is not updating the record in database. Anyone knows what the problem is..??where did i make a mistake in the code

@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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了
    • ¥50 切换TabTip键盘的输入法
    • ¥15 可否在不同线程中调用封装数据库操作的类
    • ¥15 微带串馈天线阵列每个阵元宽度计算
    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏