Skip to content
Advertisement

Record not updated using laravel

i am making a simple crud system using laravel.all working fine when i going to edit the records ran into the problem with record is not updated i didn’t get any error. get the message record updated.when i check the table it is not updated.what i tried so far i attached below Controller

   public function edit(Student $student)
    {
        return view('students.edit',compact('student'));
    }


    public function update(Request $request, Student $student)
    {
        $request->validate([

        ]);

        $student->update($request->all());

        return redirect()->route('students.index')
            ->with('success','Student updated successfully');
    }

Edit.blade.php view

 <form action="{{ route('students.update',$student->id) }}" method="POST">
        @csrf
        @method('PUT')
   
         <div class="row">

            <div class="col-xs-12 col-sm-12 col-md-12">
                <div class="form-group">
                    <strong>StudName:</strong>
                    <input type="text" name="name" value="{{ $student->studname }}" class="form-control" placeholder="Name">
                </div>
            </div>


            <div class="col-xs-12 col-sm-12 col-md-12">
                            <div class="form-group">
                                <strong>Course:</strong>
                                <input type="text" name="name" value="{{ $student->course }}" class="form-control" placeholder="course">
                            </div>
             </div>


           <div class="col-xs-12 col-sm-12 col-md-12">
                           <div class="form-group">
                               <strong>Fee</strong>
                               <input type="text" name="name" value="{{ $student->fee }}" class="form-control" placeholder="fee">
                           </div>
           </div>






            <div class="col-xs-12 col-sm-12 col-md-12 text-center">
              <button type="submit" class="btn btn-primary">Submit</button>
            </div>
        </div>
   
    </form>

Advertisement

Answer

I think the problem because of your blade file. you have to put the correct name for each input.

<input type="text" name="name" value="{{ $student->studname }}" class="form-control" placeholder="Name">
--------------------------
<input type="text" name="course" value="{{ $student->course }}" class="form-control" placeholder="Course">

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement