【发布时间】: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