简体   繁体   English

此路由不支持 GET 方法。 支持的方法:POST。 与 laravel

[英]The GET method is not supported for this route. Supported methods: POST. with laravel

在此处输入图像描述 i want to add a post in my blog so when i just click on the button submit to add the post i get this error:我想在我的博客中添加一个帖子,所以当我点击按钮提交添加帖子时,我收到此错误:

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

this is the form:这是表格:

 <form action="/add" method="POST" enctype="multipart/form-data">
    @csrf_field
    @method('POST')
    <label for="">Titre de l'article</label>
    <input type="text" class="form-control" name="title" id=""  placeholder="Titre de l'article">
    <label for=""> Description de l'article</label> </br>
    <textarea name="description" id="" cols="63" rows="20"></textarea> 
    <label for="">Image pour l'article</label>
    <input type="file" name="photo" class="form-control" id=""  placeholder="Titre de l'article">
    <input type="hidden"  class="form-control" name="articlemed" value="{{$med->ID}}" />
    <button type="submit" class="btn btn-primary"> Ajouter l'article </button>
    </form>

and this is the controller:这是 controller:

public function add (Request $request)

    {
        $blog= new blog;

        $blog-> title = $request->input('title');
        $blog ->body = $request->input('description');
        $blog->author_id=$request->input('articlemed');
        $blog ->image = $request->input('photo');
        $blog-> save();
        return back()->withSuccess(Success!' ) ; 

and finally the web.php最后是 web.php

Route::get('/index','specvil@index');

Route::get('/inscription', 'specvil@inscription');

Route::post('/ajouter','doctor@ajouter');

Route::post('/bienvenu','doctor@authentification')->name('aziz');

Route::get('/edit/{id}','rendezv@edit');
Route::post('/update/{id}','rendezv@update');

Route::get('/blog' ,'postcontroller@index');

Route::get('/blog_{post}' ,'postcontroller@show' );

Route::post('blog/{getid}/store', 'commentcontroller@store');

Route::post('/add', 'postcontroller@add')->name('newpost');

please use this once.请使用一次。

php artisan cache:clear,
php artisan route:cache,
php artisan view:clear,
composer dump-autoload

Change your route to Route::post('/add', 'postcontroller@add')->name('add');将您的路线更改为 Route::post('/add', 'postcontroller@add')->name('add'); And then in your form action然后在你的表单动作中

<form action="route('add)" method="POST" enctype="multipart/form-data"> 

and also remove @method('POST')并删除 @method('POST')

Give this a shot.试一试。

<form action="{{ route('newpost') }}" method="POST" enctype="multipart/form-data">

or或者

Remove the named route删除命名路由

Route::post('/add', 'postcontroller@add');

<form action="{{ url('/add') }}" method="POST" enctype="multipart/form-data">

Which Laravel version, you are using?您使用的是哪个 Laravel 版本? Also, I tried your code, and it works, Try as the guys said, clear your cache using另外,我尝试了您的代码,并且可以正常工作,请按照他们所说的尝试,使用清除缓存

php artisan cache:clear

and

php artisan route:clear

Also, try to remove the @csrf_field, and replace it only with @csrf, And remove also @method('POST'), because it's not needed.此外,尝试删除@csrf_field,并仅将其替换为@csrf,同时删除@method('POST'),因为它不是必需的。 Finally, double check your web.php最后,仔细检查您的 web.php

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 此路由不支持 GET 方法。 支持的方法:POST。 在 laravel 8 - The GET method is not supported for this route. Supported methods: POST. in laravel 8 此路由不支持 GET 方法。 支持的方法:POST。 拉拉维尔 8 - The GET method is not supported for this route. Supported methods: POST. laravel 8 此路由不支持 PUT 方法。 支持的方法:POST。 在 laravel 8 - The PUT method is not supported for this route. Supported methods: POST. in laravel 8 尝试登录 Laravel API:&#39;此路由不支持 GET 方法。 支持的方法:POST。 - Trying to login to Laravel API: 'The GET method is not supported for this route. Supported methods: POST.' 此路由不支持 GET 方法。 支持的方法:POST。 在 Laravel 7.24.0 - The GET method is not supported for this route. Supported methods: POST. in Laravel 7.24.0 Laravel5.8:此路由不支持 GET 方法。 支持的方法:POST。 问题 - Laravel5.8: The GET method is not supported for this route. Supported methods: POST. issue 此路由不支持 GET 方法。 支持的方法:POST。 laravel 5.8 阿贾克斯 - The GET method is not supported for this route. Supported methods: POST. laravel 5.8 Ajax 此路由不支持 GET 方法。 支持的方法:POST。 laravel-8 - The GET method is not supported for this route. Supported methods: POST. laravel-8 此路由不支持 PUT 方法。 支持的方法:GET、HEAD、POST。 在 laravel - The PUT method is not supported for this route. Supported methods: GET, HEAD, POST. in laravel 此路由不支持 GET 方法。 支持的方法:POST。 Laravel 和 Ajax - The GET method is not supported for this route. Supported methods: POST. Laravel and Ajax
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM