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

时间:2020-05-22 03:44:53

标签: php laravel

enter image description here我想在我的博客中添加帖子,所以当我单击提交按钮以添加帖子时,我会收到此错误:

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

这是表格:

 <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>

这是控制器:

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!' ) ; 

最后是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');

4 个答案:

答案 0 :(得分:1)

请使用一次。

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

答案 1 :(得分:1)

将您的路线更改为Route :: post('/ add','postcontroller @ add')-> name('add'); 然后在表单操作中

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

并删除@method('POST')

答案 2 :(得分:1)

试一下。

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

删除命名的路线

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

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

答案 3 :(得分:1)

您使用的是哪个Laravel版本? 另外,我尝试了您的代码,并且可以正常工作,正如大家所说,尝试使用

清除缓存
php artisan cache:clear

php artisan route:clear

此外,尝试删除@csrf_field,并仅将其替换为@csrf, 并也删除@method('POST'),因为它不是必需的。 最后,仔细检查您的web.php