我创建了一个库类,我正在使用它来完成Laravel未提供的一些常用功能。它被加载到'aliases'数组下的/config/app.php中,所以这应该不是问题。
当我从我的类(“InfoParse”)调用方法时,我的控制器返回一个空白页面。我认为这与我从库中调用一个使用Eloquent与数据库接口的方法有关。我尝试添加
use Illuminate\Database\Eloquent\Model;
到文件的顶部,但这也无济于事。
我是否应该以特定的方式设置我的类文件,以便可以使用DB :: class或Eloquent类?
以下是有问题的功能:
/**
* Check to see if this student is already recorded in our student table.
* If not, add the entry, then return true.
* @param int $cwid
* @return boolean
*/
public static function checkStudentTableRecords($cwid)
{
if(Student::where('cwid', '=', $cwid)->count() != 0)
{
return TRUE;
}
else
{ ##insert the student into our student table
$studentInfo = self::queryInfoFromCWID($cwid);
$studentEntry = new Student;
$studentEntry->cwid = $cwid;
$studentEntry->fName = $studentInfo['fName'];
$studentEntry->lName = $studentInfo['lName'];
$studentEntry->email = $studentInfo['email'];
$studentEntry->save();
return TRUE;
}
}
(注意:self :: queryInfoFromCWID()函数正在调用类中前面定义的函数)
答案 0 :(得分:3)
经过一番调查后发现我需要格式化我的Eloquent Model调用:
if(\Student::where('cwid', '=', $cwid)->count() != 0)
...
$studentEntry = new \Student;
反斜杠是避免Laravel4应用程序中的命名空间冲突所必需的。