我正在使用资源路由。现在,我想添加另一条路线:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
</head>
<body ng-app="myApp">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="@mdo">Send Data</button>
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" ng-controller="myCtrl">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">User Information</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<label for="recipient-name" class="col-form-label">Recipient:</label>
<input type="text" class="form-control" ng-model="recipientName">
</div>
<div class="form-group">
<label for="message-text" class="col-form-label">Message:</label>
<textarea class="form-control" ng-model="messageText"></textarea>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" ng-click="sendData();">Send message</button>
</div>
</div>
</div>
</div>
这是回复功能,
Route::resource('discussion', 'DiscussionsController');
Route::post('/discussion/reply/{id}',[
'use' => 'DiscussionsController@reply',
'as' => 'discussion.reply'
]);`
这是重定向到存储功能的刀片。
public function reply($id)
{
$discussion = Discussion::find($id);
$reply = Reply::create([
'user_id'=>Auth::id(),
'discussion_id' => $id,
'content'=> \request()->reply
]);
return redirect()->back();
}
出什么问题了?
答案 0 :(得分:1)
您在路由中使用中间件吗? 如果是,请检查您是否正在使用“ 使用”键,而不是“ 使用”键。 示例:
Route::get('foo/bar/{id}',['middleware'=>'auth','uses'=>'FooController@show']);
或者您可以仅传递控制器名称并作为第二个参数,而无需基于键值的数组。
答案 1 :(得分:-1)
我可能是错的,但是乍一看我是因为您的TypeError: clik is not a function[Learn More]
拥有use
而不是uses
。
尝试更改
Route
到
'use' => 'DiscussionsController@reply',
第二,您不需要将'uses' => 'DiscussionsController@reply',
与\
一起使用。
将其更改为\request()->reply
甚至是request()->reply
答案 2 :(得分:-2)
尝试更改路线顺序
代替
{
"birthDate": "2001-12-19",
"gender": "male"
}
使用
Route::resource('discussion', 'DiscussionsController');
Route::post('/discussion/reply/{id}',[
'use' => 'DiscussionsController@reply',
'as' => 'discussion.reply'
]);