vendredi 20 décembre 2019

The PUT method is not supported for this route. Supported methods: POST

**I have a problem when click edit button,in a edit.blade.php In update Function The PUT method is not supported for this route. Supported methods: POST. **

web.php

<?php
    Route::get('/', function () {
        return view('welcome');
    });
    Route::get('phones','PhonesController@index');
    Route::post('store','PhonesController@store');
    Route::delete('destroy/{id}','PhonesController@destroy');
    Route::put('edit/{id}', 'PhonesController@edit');
    Route::post('update/{id}','PhonesController@update');

View edit.blade.php

<div class="container">
    <div class="col-sm-offset-2 col-sm-8">
        <div class="panel panel-default">
            <div class="panel-heading">
                Edit 
            </div>

            <div class="panel-body">
                <!-- Display Validation Errors -->
                <!-- New Task Form -->
            <form action="" method="POST" 

class="form-horizontal">
                        @csrf     


<div class="form-group">
                    <div class="col-sm-offset-3 col-sm-6">    
                        <button type="submit" class="btn btn-primary">
@method('put')
                            <i class="fa fa-edit"></i> Edit
                        </button>
                    </div>
                </div>
                </form>
            </div>
        </div> 

and Controller

   public function edit($id){

            $phone= Phone::find($id);
            return view('edit',compact('phone'));

        }

        public function update(Request $request,$id){
     $this->validate($request, [
                'name' => 'required|max:10',
                'model'=>'required'
            ]);
            $phone=new Phone();
            $phone->name=$request->input('name');
            $phone->model=$request->input('model');
            $phone->save();
            return back();

        }

just this is a problem i tried another ways but still getting same problem thank you



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire