lundi 4 décembre 2017

Laravel: Passing variable from Blade to relationship not working

I am trying to modify a Laravel relationship to return the related case against a question.

My question model has the following relationship entry:

/**
 * A Question has one Case Detail
 *
 * @return \Illuminate\Database\Eloquent\Relations\HasOne
 */
public function casedetail( $caseId ) {


    return $this->hasOne( 'App\CaseDetail' )->where( 'test_case_id', $caseId );


}

However, trying to access the casedetail from Blade using a variable like this:



Is returning me the following error:

"htmlspecialchars() expects parameter 1 to be string, object given (View: /home/vagrant/Code/TestBench/resources/views/testcases/category_questions.blade.php)"

If I substitute $caseId for a specific number and remove the variable request from the method then my query works fine:

return $this->hasOne( 'App\CaseDetail' )->where( 'test_case_id', 2 );

Result:

{"id":1,"test_case_id":2,"question_id":1,"result_type":0,"result":"now what","tester_id":1,"attachment":null,"created_at":"2017-11-30 03:17:42","updated_at":"2017-12-04 06:57:40"}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire