So, maybe i'm not connecting the dots very well, between my models. I get the error:
Argument 1 passed to RespuestaController::postRespuesta() must be an instance of Question, string given
when i pass the Question model in my view:
{{ Form::open( array( 'action' => array( 'RespuestaController@postRespuesta', $question->id ) ) ) }}
Here's my app/routes.php:
Route::model('respuesta', 'Respuesta');
Route::model('question', 'Question');
Route::resource('questions', 'QuestionController');
Route::controller('respuestas', 'RespuestaController');
and the RespuestaController:
class RespuestaController extends \BaseController {
public function postRespuesta(Question $question)
{
$validator = Validator::make(Input::all(),
array(
'respuesta' => 'required'
)
);
if( $validator->fails() ){
return Redirect::route('questions.show')
->withErrors($validator);
}else{
$respuesta = Input::get('respuesta');
$respuesta = Respuesta::create(array(
'respuesta' => $respuesta
)
);
$respuesta->save();
$question->respuesta()->associate($respuesta)->save();
$respuesta->user()->associate(Auth::user())->save();
//$question = Question::find($question); //this works without (Question $question), but i think is not a good practice or is it??
}
}
}
Am i doing the model binding right?? Or is just for routes created manually instead of only Route::controller('respuestas', 'RespuestasController');
Thanx for your support.