lundi 2 septembre 2019

Update and delete -- i can't update and delete data from database in laravel framework

i am using a form to submit my request to update and delete my data from database but i am unable to do so .As i am noob at laravel i want someone to help me sort out this silly problem i have.

i have tried using differents methods but i could not solve this problem. i am using laravel 5.4.36 for this project.

controller--->(updatemethod)

                public function update(Request $request, $id)
                    {
           Student::where('id', $id)->update(['first_name' => 'vks', 'last_name' => 'pok']);
}

controller-->(deletemethod)enter code here

          public function destroy(Request $id)
{
 $student=Student::find($id);
     $student->delete();
   }

route->

    Route::get('/student/about', 'BksController@about');
     Route::get('/student/service', 'BksController@Services');
     Route::get('create','BksController@create');
     Route::post('create','StudentController@create');
    Route::get('search','BksController@search');
    Route::post('search','StudentController@show');
      Route::get('/update','BksController@update');
   Route::put('update','StudentController@update');
      Route::get('/delete','BksController@delete');
       Route::delete('/delete','StudentController@destroy');
         Route::resource('student', 'StudentController');
      Route::get('/home', 'HomeController@index')->name('home');

delete.blade.php->

       @include('student.commonlayout')
      <div class='col-md-6 col-md-offset-3'>
         <h1>DeleteData</h1>
          <hr>
             <form method="post" action="">
            
             <div class="form-group">
              <input type="text" name="first_name" class="form-control" 
       placeholder="Enter your Id" />
        </div>
      <div class="form-group">
        <input type="submit" class="btn btn-primary"/>
        </div>
      </form>
       </div>

update.blade.php-->

      @include('student.commonlayout')
       <div class='col-md-6 col-md-offset-3'>
  <h1>update Data</h1>
<hr>
<form method="post" action="">
    
    <div class="form-group">
        <input type="text" name="id" class="form-control" placeholder="Enter your id" />
    </div>
    <div class="form-group">
        <input type="text" name="first_name" class="form-control" placeholder="Enter your Name" />
    </div>
    <div class="form-group">
        <input type="text" name="last_name" class="form-control" placeholder="Enter last Name" />
    </div>


    <div class="form-group">
        <input type="submit" class="btn btn-primary"  />
    </div>
</form>

on pressing update submit error->

          MethodNotAllowedHttpException
      in RouteCollection.php line 251

on pressing delete submit error->

         MethodNotAllowedHttpException
     in RouteCollection.php line 251




Aucun commentaire:

Enregistrer un commentaire