2016-11-25 66 views
0

我一直在研究一個web應用程序最近在laravel,我想在應用程序中有一個eddit函數。但我得到這個錯誤[路線:producten.update] [URI:producten/{producten}]缺少必要的參數,我不知道我做錯了什麼。在更新表單中缺少必需的參數Laravel 5.2

這是使用即時通訊路線:

Route::resource('producten', 'ProductenController', ['only' => ['index', 'store', 'update', 'delete', 'edit', 'destroy', 'create']]); 

這是使用用於示出編輯頁面和更新控制器功能IM。

編輯功能

public function edit(Request $request, Product $product) 
{ 
    // $product = Product::FindorFail($id); 
    // Product is a table with all products, with sellprice and buy price 
    // fabriek = table that has a foreign key attached to the product table 
    return view('producten.edit', [ 
     'model' => $product, 
     'fabrieks' => Fabriek::lists('Id') 
     ]); 

} 

的更新功能:

public function update(Request $request, Product $product) 
    { 

     $product->update($request->all()); 

     return redirect(Route('producten.index')); 

    } 

,這是我使用它的視圖。

{{Form::model($model, ['method' => 'PATCH', 'action' => '[email protected]', $model ]) }} 

    {{ Form::label('naam:')}} 
    {{ Form::text('naam') }} <br> 

    {{ Form::label('inkoopPrijs:')}} 
    {{ Form::text('inkoopPrijs') }} <br> 

    {{ Form::label('verkoopPrijs:') }} 
    {{ Form::text('verkoopPrijs') }} <br> 

    {{Form::label('Fabrieken', 'Fabrieken Id:') }} 
    {{ Form::select('Fabrieken_Id', $fabrieks)}} <br> 
    {{ Form::submit('edit')}} 
    {{ Form::close() }} 

如果有別的,我需要補充的問題只是讓我知道,我會添加它

+0

你在你的函數體內有一個說法,「請求$請求,產品$產品」從它將採取?它如何通過你定義的路線? – Rupal

回答

3

缺少的是你是不是在你的編輯功能 越來越ID那裏的ID你的編輯功能應該我假設你只是顯示此方法的形式,其中用戶可以編輯

public function edit($id) 
{ 
     $product = Product::FindorFail($id); 
     //Product is a table with all products, with sellprice and buy price 
     //fabriek = table that has a foreign key attached to the product table 
     return view('producten.edit', [ 
     'model' => $product, 
     'fabrieks' => Fabriek::lists('Id') 
     ]); 

} 

您的更新方法應該看起來像這樣

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

    $product->update($request->all()); 

    return redirect(Route('producten.index')); 

} 

你的路線應該喜歡這個沒有必要只

Route::resource('/producten', 'productionController'); 

編輯路線將作爲

<a href="{{ route('production.edit', $model->id) }}"> 

試試這個希望這將有助於

+0

我已將'action'=>'ProductenController @ update'更改爲'Route'=>'Producten.update',$ model-> Id,並將$ id添加到函數中,並且它似乎可行,但現在當我按下編輯按鈕時,出現MethodNotAllowedHttpException錯誤,你知道如何解決它嗎? –

+0

你不需要寫更新的路由只是爲編輯寫,然後你的數據會自動傳遞更新,你可以更新爲 '

+0

我有更新我的問題,請檢查它 –

相關問題