Laravel ErrorException-缺少参数2

时间:2016-03-26 15:57:17

标签: laravel

我正在尝试更新时收到此错误消息。我很感激任何帮助!这是我的路线档案:

Route::get('shelter/articles', ['as' => 'admin.shelter.articles', 'uses' => 'ArticlesController@index']);
Route::get('shelter/article/create', ['as' => 'admin.shelter.article.create', 'uses' => 'ArticlesController@create']);
Route::post('shelter/article/store', ['as' => 'admin.shelter.article.store', 'uses' => 'ArticlesController@store']);
Route::get('shelter/article/edit/{id}', ['as' => 'admin.shelter.article.edit', 'uses' => 'ArticlesController@edit']);
Route::put('shelter/article/update', ['as' => 'admin.shelter.article.update', 'uses' => 'ArticlesController@update']);

这是我的控制者:

 public function update(EditRequest $request, $id){

$data=[];
$article = Article::findOrFail($id);
$slug = str_slug($request['name']);
if($slug!=$article->slug)
    $data=['slug' => $slug];
$article->fill(array_merge($this->fillobject($request), $data))
    ->update();
if($request->hasFile('upload_files'))
    $this->fileUpload($request->file('upload_files'), $article->id);

return Redirect::route('admin.shelter.article.edit',['id'=>$article->id]);}

这是我的形式:

{!! Form::model($article, ['method' => 'PUT', 'route' => ['admin.shelter.article.update', 'id' => $article->id], 

3 个答案:

答案 0 :(得分:1)

试试这个:

{{1}}

答案 1 :(得分:0)

您未在更新路线中指定参数:

Route::put('shelter/article/update', ['as' => 'admin.shelter.article.update', 'uses' => 'ArticlesController@update'])

只需将{id}路由参数添加到更新路径,就像在编辑路径

中一样

答案 2 :(得分:0)

首先将路线更改为

$scope.foo = {
    poste : "poste",
    name: "name"   
}
$scope.SendData = function () {
   var req = {
       method: 'POST',
       url: 'http://localhost:8080/addPr',
       headers: {
          'Content-Type': 'application/json'
       },
       data: {'nom':$scope.foo.poste, 'poste':$scope.foo.name}
   }
    $http(req).then(function(){
           alert('success');
        }, function(){
           alert(error.error);
    });
};

然后将表单更改为

Route::put('shelter/article/update/{id}', ['as' => 'admin.shelter.article.update', 'uses' => 'ArticlesController@update']);