2016-10-17 10 views
0

データベースの行を更新する際に問題が発生しました。私が更新フォームを提出するとすぐに、返信とエラーCall to a member function update() on null誰かが私がここで間違っていることを教えてもらえますか?Laravel 5.3の更新行が、nullのメンバー関数update()にコールを返します。

マイコード:

public function update(Request $request){ 
     $user = Auth::user(); 
     $uid = $user->farmTag; 

     $cowValues = array(
      'KilledOn' => $request['KilledOn'], 
      'EID' => $request['EID'], 
      'ManagementI/D' => $request['ManagementID'], 
      'name' => $request['name'], 
      'breed' => $request['breed'], 
      'sex' => $request['sex'], 
      'DOB' => $request['DOB'], 
      'BoughtOn' => $request['BoughtOn'], 
      'description' => $request['description'], 
      'farmTag' => $uid, 
    ); 

     Cow::find($request['EID'])->update($cowValues); 

     return back(); 

    } 

全エラー:

in CowsController.php line 280 
at CowsController->update(object(Request)) 
at call_user_func_array(array(object(CowsController), 'update'), array(object(Request))) in compiled.php line 9355 
at Controller->callAction('update', array(object(Request))) in compiled.php line 9382 
at ControllerDispatcher->dispatch(object(Route), object(CowsController), 'update') in compiled.php line 8440 
at Route->runController() in compiled.php line 8421 
at Route->run(object(Request)) in compiled.php line 8117 
at Router->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 53 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in compiled.php line 9948 
at SubstituteBindings->handle(object(Request), object(Closure)) in compiled.php line 9840 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Authenticate.php line 43 
at Authenticate->handle(object(Request), object(Closure)) in compiled.php line 9840 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in compiled.php line 3121 
at VerifyCsrfToken->handle(object(Request), object(Closure)) in compiled.php line 9840 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in compiled.php line 13430 
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in compiled.php line 9840 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in compiled.php line 11874 
at StartSession->handle(object(Request), object(Closure)) in compiled.php line 9840 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in compiled.php line 13176 
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in compiled.php line 9840 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in compiled.php line 13113 
at EncryptCookies->handle(object(Request), object(Closure)) in compiled.php line 9840 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in compiled.php line 9825 
at Pipeline->then(object(Closure)) in compiled.php line 8118 
at Router->runRouteWithinStack(object(Route), object(Request)) in compiled.php line 8109 
at Router->dispatchToRoute(object(Request)) in compiled.php line 8100 
at Router->dispatch(object(Request)) in compiled.php line 2446 
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in compiled.php line 3183 
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in compiled.php line 9840 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in compiled.php line 9825 
at Pipeline->then(object(Closure)) in compiled.php line 2390 
at Kernel->sendRequestThroughRouter(object(Request)) in compiled.php line 2374 
at Kernel->handle(object(Request)) in index.php line 53 

一部欠落している情報があれば、私に知らせてください。

ありがとうございます!

+0

を試してみてください::($要求[ 'EID'])'戻っ 'NULL'を見つけるので、あなたのコードは'実際に 'nullで>更新($ cowValues)であります(これはまさにエラーの内容です)。 'find'の定義がなければ、本当に助けが難しいです。 – Dekel

+0

where句で検索しようとすると 'dd(Cow :: find($ request ['EID']))'を入れて何が吐き出されているのかを見てみましょう 'Cow :: where( 'EID'、$ request [ 'EID']) ' – Carlos

+0

あなたのお返事ありがとう@Carlos、あなたのアプローチは働いた!面白いのは、他の場所で同じアプローチを使用していて、そこではうまくいきました。とにかくありがとうございました! –

答えて

0

それは牛 `のように見えるこの

$cow = Cow::where('EID', $request->input('EID'))->first(); 

if($cow) 
{ 
    $cow->update($cowValues); 
} 
+0

私はこの回答で何の問題も見ません、なぜdownvote – ggderas

+0

私は彼らが好きではないと思う:P – Vikash

関連する問題