Home > other >  "The GET method is not supported for this route. Supported methods: POST ."
"The GET method is not supported for this route. Supported methods: POST ."

Time:04-24

I'm trying to add a new Post but whenever i submit i get the above error message.

This is Route:

Route::get('/p/create' , [App\Http\Controllers\PostsController::class, 'create']);
Route::post('/p' , [App\Http\Controllers\PostsController::class, 'store']);

and this is my controller:

{
    public function create(){
        return  view('posts.create');
    }

    public function store(){

        $data = request()->validate([
            'caption'=>'required',
            'image'=>'required|image',
        ]);


        $imagePath =request('image')->store('uploads' ,'public');

      //  auth()->user()->posts()->create($data);

        auth()->users()->posts()->create([

            'caption' => $data['caption'],
            'image' => $imagePath,
        ]);


        //dd(request()->all() );

        return redirect('/profile/' . auth()->user()->id);
    }
}

Anyone faced the same problem?

CodePudding user response:

Your problem is in your client side .

You should submit your form with post method not get. for example this form send post method :

<form action="{{route('example_route')}}" method='post' >
//some html here
</form>

CodePudding user response:

Try Modifying the store method to

public function store(Request $request){

        $data = $request->validate([
            'caption'=>'required',
            'image'=>'required|image',
        ]);
//...
  • Related