我正在将我的控制器从定义的get / post移动到一个宁静的变种。虽然我的Get方法正在运行,但我在post方法中遇到了关于缺少参数的问题。在我的路线中专门命名get / post时,两者都在工作。
你看到我犯的错误了吗? TIA
我得到的错误是:
Missing argument 1 for ContractorController::postLogos()
这是我的路线:
Route::controller('/contractors', 'ContractorController');
这是我的ContractorController:
public function getLogos($id)
{
//
$contractor = Contractor::find($id);
return View::make('contractors.logos')
->with('contractor', $contractor);
}
public function postLogos($id){
$contractor = Contractor::find($id);
$input = Input::all();
$rules = array(
'file' => 'image|max:3000',
);
$validation = Validator::make($input, $rules);
if ($validation->fails())
{
return Response::make($validation->errors->first(), 400);
}
$file = Input::file('file');
$destinationPath = 'uploads/logos';
//$filename = $file->getClientOriginalName();
$extension = $file->getClientOriginalExtension();
$filename = str_random(12).".{$extension}";
$upload_success = Input::file('file')->move($destinationPath, $filename);
$path = Input::file('file')->getRealPath();
if( $upload_success ) {
##$contractor = Contractor::find($id);
##$logo = new Logo(array('name' => Input::file('file')->getRealPath()));
##$logo = $contractor->logo()->save($logo);
$logo = new Logo;
$logo->name = $destinationPath ."/". $filename;
$logo->contractor_id = (Input::get('contractor_id'));
$logo->save();
return Response::json('success', 200);
} else {
return Response::json('error', 400);
}
}
我的观点:
{{ Form::open(array('action' => array('ContractorController@postLogos'),'files' => true, $contractor->id)) }}
<div class="span6 bdb bdb-larger">
<input type="file" class="filestyle" name="file" id="file" accept="image/*">
<script>$(":file").filestyle({classInput: "input-small"});</script>
<input type="hidden" name="contractor_id" value="{{$contractor->id}}">
<input type="submit" class="btn btn-primary" value="Submit">
{{Form::close()}}
</div>
答案 0 :(得分:0)
所以我想出了问题所在。
表单不能像在后期路由中那样调用方法,它必须调用视图。所以我改变了:
{{ Form::open(array('action' => array('ContractorController@postLogos'),'files' => true, $contractor->id)) }}
到:
{{ Form::open(array('url' => 'contractors/logos/{$id}','files' => true, $contractor->id)) }}
现在效果很好。