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="{{route('profile.create')}}" 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'); } }
Advertisement
Answer
Look you are using only two routes. One is for index and one is for storing. Where is the route that goes to the create page?? Add that route and controller method.
Route::get('user/profile','UserController@index')->name('profile.index'); Route::get('user/profile/create', 'UserController@create')->name('profile.create'); Route::post('user/profile/store', 'UserController@store')->name('profile.store');
Controller
class UserController extends Controller { public function index() { return view('profile.index'); } public function create() { return view('profile.create'); } 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'); } }
Form
<form action="{{route('profile.store')}}" method="POST">
And your create profile button
<a href="{{ route('profile.crate') }}"><button>Create Profile</button></a>