我做了回复功能,但效果不好..请帮帮我..
是创建回复的刀片
<div class="media media__create__comment {{ isset($parentId) ? 'sub' : 'top' }}">
<div class="media-body">
<form method="POST" action"{{ route('articles.comments.store', $article->id) }}" class="form-horizontal">
{!! csrf_field() !!}
@if(isset($parentId))
<input type="hidden" name="parent_id" value="{{ $parentId}}">
@endif
<div class"form-group {{ $errors->has('content') ? 'has-error' : '' }}">
<textarea name ="content" class="form-control">{{ old('content') }}</textarea>
{!! $errors->first('content', '<span class="form-error">:message</span>') !!}
</div>
<button type="submit" class="btn btn-primary btn-sm">
전송하기
</button>
</div>
</form>
</div>
</div>
它是控制器
<?php
namespace App\Http\Controllers; //171029
use Illuminate\Http\Request;
class CommentsController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function store(\App\Http\Requests\CommentsRequest $request, \App\Article $article)
{
$comment = $article->comments()->create(array_merge($request->all(), ['user_id'=> $request->user()->id] ));
return redirect(route('articles.show', $article->id) .'#comment_'.$comment->id);
}
}
Route::resource('comments', 'CommentsController', ['only' => ['update', 'destroy']]);
Route::resource('articles.comments', 'CommentsController', ['only' => 'store']);
错误内容是 Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException 没有消息
我搜索了3个小时.. 如果我使用PUT方法它没有错误但它改变文章的内容而不回复..请帮助我!感谢阅读本文
+--------+-----------+-----------------------------+-------------------------+-------------------------------------------------+--------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+-----------+-----------------------------+-------------------------+-------------------------------------------------+--------------+
| | GET|HEAD | / | | Closure | web |
| | GET|HEAD | api/user | | Closure | api,auth:api |
| | GET|HEAD | articles | articles.index | App\Http\Controllers\ArticlesController@index | web |
| | POST | articles | articles.store | App\Http\Controllers\ArticlesController@store | web |
| | GET|HEAD | articles/create | articles.create | App\Http\Controllers\ArticlesController@create | web |
| | DELETE | articles/{article} | articles.destroy | App\Http\Controllers\ArticlesController@destroy | web |
| | PUT|PATCH | articles/{article} | articles.update | App\Http\Controllers\ArticlesController@update | web |
| | GET|HEAD | articles/{article} | articles.show | App\Http\Controllers\ArticlesController@show | web |
| | POST | articles/{article}/comments | articles.comments.store | App\Http\Controllers\CommentsController@store | web,auth |
| | GET|HEAD | articles/{article}/edit | articles.edit | App\Http\Controllers\ArticlesController@edit | web |
| | DELETE | comments/{comment} | comments.destroy | App\Http\Controllers\CommentsController@destroy | web,auth |
| | PUT|PATCH | comments/{comment} | comments.update | App\Http\Controllers\CommentsController@update | web,auth |
| | GET|HEAD | login | sessions.create | App\Http\Controllers\SessionsController@create | web,guest |
| | POST | login | sessions.store | App\Http\Controllers\SessionsController@store | web,guest |
| | GET|HEAD | logout | sessions.destroy | App\Http\Controllers\SessionsController@destroy | web |
| | GET|HEAD | main | | Closure | web |
| | GET|HEAD | usb | | App\Http\Controllers\UsbController@index | web |
+--------+-----------+-----------------------------+-------------------------+-------------------------------------------------+--------------+
这是我的路线:列表..
答案 0 :(得分:0)
为什么只有两个控制器用于存储而另一个用于更新和删除更好,您将存储功能移动到CommentsController
控制器。
然后将路线更改为{{ route('comments.store')}}
。
希望这会对你有所帮助