mardi 17 septembre 2019

Laravel5.8: The GET method is not supported for this route. Supported methods: POST. issue

I am setting user profile update section. But when I went to profile create page, I got a following error.

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

I tried php artisan route:clear and checked everything. But I couldn't solve this issue, so I am glad if someone helps me out.

web.php

Route::get('user/profile','UserController@index')->name('profile.index');
Route::POST('user/profile/create', 'UserController@store')->name('profile.create');

create.blade.php

<form action="" method="POST">@csrf

                    <ul class="information">
                        <li>Name :<br>
                            <input type="text" class="name" name="name">
                        </li><br>
                        <li>Gender :<br>
                            <div class="gender">
                                <select name="gender" id="" name="gender">
                                    <option class="option" value="" selected="selected">Select Gender</option>
                                    <option value="" >Male</option> 
                                    <option value="United States" class="selected">Female</option> 
                                    <option value="United Kingdom">Any</option> 
                                </select>       
                            </div>
                        </li>   
                        <li>Country :<br>
                            <div class="country">
                                <select name="country" id="" name="country">
                                    <option value="" selected="selected">Select Country</option> 
                                    <option value="United States" class="selected">United States</option> 
                                    <option value="United Kingdom">United Kingdom</option> 
                                </select>
                            </div>    
                        </li><br>
                        <li>Birthday :<br>
                            <input type="text" class="birthday" id="bod" name="bod">
                        </li><br>
                        <li>User Description :<br>
                            <textarea name="description" id="" cols="60" rows="10"></textarea></li>
                    </ul>
                    <button type="submit" class="saveBtn">Save</button>
                </div>
            </form>

profile table

public function up()
    {
        Schema::create('profiles', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('user_id');
            $table->string('image');
            $table->string('name');
            $table->string('gender');
            $table->string('country');
            $table->string('bod');
            $table->string('description');
            $table->timestamps();
        });
    }

UserController.php

class UserController extends Controller
{
    public function index() {
        return view('profile.index');
    }

    public function store(Request $request) {
        $user_id = auth()->user()->id;


        Profile::where('user_id',$user_id)->update([
            'name'=>request('name'),
            'gender'=>request('gender'),
            'country'=>request('country'),
            'bod'=>request('bod'),
            'description'=>request('description')
        ]);

        return redirect()->route('profile.index');

    }
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire