问题描述
<?PHP
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class universityController extends Controller
{
//
public function getStudents(Request $req)
{
$students= DB::table('students')
->join('applicants',function ($join) {
$join->on('students.id','=','applicants.studentid')
->where('applicants.scholarshipid',$req->scholarshipid);
})
->get();
return $students;
// return $req->scholarshipid;
}
}
解决方法
正如 @lagbox 提到的,你在一个匿名函数中,它无法到达外部作用域
所以要解决这个问题,你需要像这样使用 use
public function getStudents(Request $req)
{
$students= DB::table('students')
->join('applicants',function ($join) use($req) {
$join->on('students.id','=','applicants.studentid')
->where('applicants.scholarshipid',$req->scholarshipid);
})
->get();
return $students;
// return $req->scholarshipid;
}
有关 anonymous function
的更多信息,请查看此处的 docs
使用匿名变量
$students= DB::table('students')
->join('applicants',function ($join) use ($req) {
$join->on('students.id',$req->scholarshipid);
})
->get();
了解更多 cmake FindBoost not finding Boost libraries when building with MinGW on Windows