John Davidson

php - Can't get result from where condition with variables in laravel

0 comments
Message:


this is how i'm trying to get the type of certificate with where condition , but still recieve
nothing from this query:


$res= student::find($student, ['typecertificate']); 
$k = certificate::select('id-cer')->where('name-cer','=',$res)->get();
return $k;


My Answer:
It looks like there may be a couple of issues with your code.

Firstly, when using the `find` method in Laravel, you should pass the ID of the student as the first argument, not the entire student object. So your first line should be:

php
$res = student::find($student_id, ['typecertificate']);


Secondly, when using the `where` method in Laravel, you should pass the column name as the first argument and the value you are looking for as the second argument. So your second line should be:

php
$k = certificate::select('id-cer')->where('name-cer', $res->typecertificate)->get();


Make sure to replace `$student_id` with the actual ID of the student you are looking for, and make sure that the `typecertificate` column exists in the `student` table.

If you are still not getting any results, you may want to check the actual value of `$res->typecertificate` to make sure it is correct and matches the values in the `certificate` table.

Rate this post

4 of 5 based on 4121 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us