2016-12-08 5 views
0

この方法を使用して画像をアップロードし、ページIDを渡すと、パスをデータベースに保存できますが、エラーが発生します。「App \ Http \ Controllers \ RoundtablesControllerの引数2がありません:: postImage()idをコントローラに渡す方法5.2

これはこれはこれは私のコントローラである私のルート

Route::post('/roundtables/settings',['uses'=>'[email protected]','middleware'=>['auth']]); 

である私のフォーム

<div class="btn-group"> 
         {!! Form::open(array('action' => '[email protected]',$tables->id, 'files'=>true)) !!} 

         <div class="form-group"> 
          {!! Form::label('Profile-Picture', 'Profile Picture:') !!} 
          {!! Form::file('profile_image',null,['class'=>'form-control']) !!} 
         </div> 

         <div class="form-group"> 
          {!! Form::submit('Save', ['class' => 'btn btn-primary form-control']) !!} 
         </div> 
         {!! Form::close() !!} 
        </div> 

である」、$名はページIDを取得しますが、IDのようではないはず哀愁dからここまで

public function postImage(Request $request,$name){ 
    $table_details =Detail::find($name); 
    //save image 
    if ($request->hasFile('profile_image')) { 
     //add new photo 
     $image = $request->file('profile_image'); 
     $filename = time() . '.' . $image->getClientOriginalExtension(); 
     $location = public_path('images/' . $filename); 
     Image::make($image)->resize(800, 400)->save($location); 
     $oldFilename = $table_details->profile_image; 

     //update database 
     $table_details->profile_image = $filename; 
     //Delete old image 
     Storage::delete($oldFilename); 
    } 
    $table_details->update(); 

エラーはどこですか? Sry私はこれが非常に基本的だと知っていますが、私はlaravelに新しいです。

答えて

0

ルートのようにする必要があります:

Route::post('/roundtables/settings/{id}', 
    ['as' => 'roundtables.setting', 
    'middleware'=>['auth'], 
    'uses'=>'[email protected]']); 

処置:

などのオープン形式のビューで
public function postImage(Request $request, $id) { 
    $Detail = Detail::findOrFail($id); // will return 404 or exception if record not found 

    if ($request->hasFile('profile_image')) { 
    $file = $request->file('profile_image'); 
    $profile_image = time() . '.' . $file->getClientOriginalExtension(); 
    $profile_image_file = public_path('images/' . $profile_image); 
    Image::make($image) 
      ->resize(800, 400) 
      ->save($profile_image_file); 

    $old_profile_image_file = public_path('images/'.$Detail->profile_image); 

    if(is_file($profile_image_file)) { // if new file successfully created 
     $Detail->profile_image = $profile_image; // changing profile_image 
     $Detail->save(); // saving 
     Storage::delete($old_profile_image_file); 
    } 
    } 
} 

(使用という名前のルート:roundtables.settingは、ルータに定義されている):

{!! Form::open(array('url' => route('roundtables.setting', $tables->id), 'files'=>true)) !!} 



もそれはあなたは$tablesは、モデルのインスタンス(ない配列またはコレクション)であることを確認し、$tables->id少し奇妙されているのか?

+0

コードを変更した後、「[Route:] [URI:roundtables/settings/{id}]の必須パラメータがありません。私のフォームはIDを渡さないのですか? – masterhunter

+0

@masterhunterは私の答えのチェックを更新しました。また、あなたは '$ tables'を取得して、あなたの行動を見て渡してください。 – num8er

+1

route( 'rountables.setting'、$ tables-> id)にタイプミスがありましたが、うまくいきました。ありがとうございました。私はまだデータを渡すことに慣れていない。 – masterhunter

0

ルートは

Route::post('/roundtables/settings/{name}',['uses'=>'[email protected]','middleware'=>['auth']]); 
0

この方法を試してみてください...

ルート::( 'グループ/(:任意の)' を取得、配列は、(=> 'グループ' 'と'、)=> 'ショー@グループ' '使用しています' );

class Groups_Controller extends Base_Controller { 

    public $restful = true;  

    public function get_show($groupID) { 
     return 'I am group id ' . $groupID; 
    } 


} 
関連する問題