2017-02-02 4 views
2

Ich habe ein Formular :: Modell Ich habe erstellt, wenn ein Datensatz ausgewählt wird Informationen in einem Formular angezeigt, wenn ich es bearbeiten möchte, erhalte ich einen Fehler. , das sagt:Laravel 5.0 Update Formular funktioniert nicht

exception 'InvalidArgumentException' with message 'Route [test/edit] not defined.' in /www/testsite/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php:306 

routes.php

Route::any('test/edit','Test\[email protected]'); 

edit.blade.php

{!! Form::model($display,array('url' => array('test/edit',$display->myID),'method' => 'put')) !!} 


        {!! Form::label('myID', 'My ID') !!} 
        {!! Form::text('myID') !!} 

         {!! Form::label('topic', 'Topic') !!} 
         {!! Form::text('topic') !!} 
         <br> 
         {!! Form::label('describe', 'describe') !!} 
         {!! Form::text('describe') !!} 
         <br> 
    {!! Form::submit('Update') !!} 

         {!! Form::close() !!} 

testController.php

public function edit($id,Request $request) 
    { 
     $myID = $request->myID; 
     $topic = $request->topic; 
     $descibe = $request->descibe; 

     $validator = \Validator::make(
      array(
       'myID' => $myID, 
       'topic' => $topic, 
       'descibe' => $descibe 
      ), array(
       'myID' => 'required|min:1', 
       'topic' => 'required|min:2', 
       'descibe' => 'required|min5' 
      ) 
     ); 
$test = Test::find($id); 
     $test->save(); 
} 

Antwort

0

ein Verfahren "Patch" ist in Laravel gegeben, Sie können es verwenden . Es funktioniert für mich in meiner Update-Funktion, d. H.

public function update(Request $request, $id) 
{ 
    $this->validate($request, [ 
     'name' => 'required', 
     'details' => 'required', 
    ]); 

    $input = $request->all(); 

    if ($request->hasFile('userpic')) { 
     $userpic = $input['pic']; 
     $file_path = public_path("avatars/$userpic"); 
     if(File::exists($file_path)) { 
      File::delete($file_path); 
     } 
     $fileName = time().$request->userpic->getClientOriginalName(); 
     $request->userpic->move(public_path('avatars'), $fileName); 
     $input['userpic'] = $fileName; 
    }  
    Product::find($id)->update($input); 
    return redirect()->route('productCRUD.index')->with('success','Product updated successfully'); 
} 
+0

Bitte geben Sie mir Antwort funktioniert oder nicht –