【问题标题】:The GET method is not supported for this route. Supported methods: POST. with laravel此路由不支持 GET 方法。支持的方法:POST。与 laravel
【发布时间】:2020-05-22 03:44:53
【问题描述】:

我想在我的博客中添加一个帖子,所以当我点击按钮提交添加帖子时,我收到了这个错误:

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

【问题讨论】:

  • 如果我是你,我将更改为 Route::get('/add', 'postcontroller@add'); 以检查我是否正确重定向到此路由,其次 @method('POST') 在您的 HTML 中有点多余。
  • 我已经改过了,但我得到了同样的错误
  • 你能用action={{url('add')}}试试吗
  • @MekjkrhG 同样的错误
  • 你能检查你的 php artisan route:list

标签: php laravel


【解决方案1】:

请使用一次。

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

【讨论】:

  • 你有与这条路线相同的重复路线吗??
  • 不,我不确定
【解决方案2】:

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

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

同时删除@method('POST')

【讨论】:

  • 同样的问题 :(
  • 你检查你的路由列表 php artisan route:list 了吗?
  • 是的,我没找到他
  • 你能发布你的 web.php 和 route:list 结果吗
  • 我把它添加到我的帖子中你可以查看它
【解决方案3】:

试一试。

&lt;form action="{{ route('newpost') }}" method="POST" enctype="multipart/form-data"&gt;

删除命名路由

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

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

【讨论】:

    【解决方案4】:

    您使用的是哪个 Laravel 版本? 另外,我尝试了您的代码,并且可以正常工作,请按照他们所说的尝试,使用

    清除缓存
    php artisan cache:clear
    

    php artisan route:clear
    

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

    【讨论】:

      猜你喜欢
      • 2021-04-11
      • 2021-08-05
      • 2020-06-05
      • 2020-03-21
      • 2021-01-10
      • 2020-04-19
      • 1970-01-01
      • 2020-09-04
      相关资源
      最近更新 更多